在VB 6.0中动态加载OCX

时间:2012-03-30 07:32:37

标签: winapi vb6 activex

我在VB 6.0中动态加载OCX。

以下是我用来加载和调用方法的代码:

Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long 
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long 
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long 
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long 

Private Sub Foo 
  On Error Resume Next 

  Dim lb As Long, pa As Long 
  Dim versionString As String 
  Dim retValue as Long 

  lb = LoadLibrary("D:\projects\other\VB_DLLs\TestDLL\TestDLL.dll")   

  'retrieve the address of getVersion' 
  pa = GetProcAddress(lb, "getVersion") 

  'Call the getVersion function' 
  retValue = CallWindowProc (pa, Me.hWnd, "I want my version", ByVal 0&, ByVal 0&) 

  'release the library' 
  FreeLibrary lb 
End Sub 

现在我想访问OCX的公共属性。我如何访问(获取/设置)OCX的属性?

1 个答案:

答案 0 :(得分:3)

您不能以这种方式使用OCX / COM控件。

要创建和使用对象的实例,您需要...创建对象的实例,然后使用它。

Set TestObject = CreateObject("TestDll.TestObject")
Value = TestObject.Method(InputValue)

这需要注册DLL,并且将使用注册的而不是特定的实例。

如果您不想注册,请查看DirectCOM。