P
Paul Coene
I've spent the better part of the day trying to figure out how to utilize
an unmanaged DLL dynamically from VB.Net. I've figured out how to get the
library loaded, and set up delegates for the DLL.
What I can't get to work, or see how to do, is pass arguments to
DynamicInvoke that will get filled in. The DLL API wants long * to fill
in
My example below:
Private Declare Auto Function LoadLibrary Lib "kernel32.dll" (ByVal
ProcName As String) As Integer Private Declare Ansi Function
GetProcAddress Lib "kernel32.dll" (ByVal ModuleHandle As Integer, ByVal
ProcName As String) As Integer
Private Delegate Function dPassThruOpen(ByRef reserved As Integer,
ByRef DeviceId As Integer) As Integer
....
Dim ModuleHandle As Integer
Dim OpenMethodPointer As Integer
Dim temp As Integer
Dim ret As Long
Dim arg() As Object
Dim deviceId As Integer
ModuleHandle = LoadLibrary(myInstance.dllpath)
OpenMethodPointer = GetProcAddress(ModuleHandle, "PassThruOpen")
temp = 0
arg = New Object() {temp, deviceId}
ret = Marshal.GetDelegateForFunctionPointer(OpenMethodPointer,GetType(dPassThruOpen)).DynamicInvoke(arg)
ke(arg)
......
The above gets a valid ModuleHandle. A Valid OpenMethodPointer. The call to DynamicInvoke succeeds
and the ret provided makes sense (as it would have come from the DLL). However, the deviceId is not
filled in. What am I doing wrong?
an unmanaged DLL dynamically from VB.Net. I've figured out how to get the
library loaded, and set up delegates for the DLL.
What I can't get to work, or see how to do, is pass arguments to
DynamicInvoke that will get filled in. The DLL API wants long * to fill
in
My example below:
Private Declare Auto Function LoadLibrary Lib "kernel32.dll" (ByVal
ProcName As String) As Integer Private Declare Ansi Function
GetProcAddress Lib "kernel32.dll" (ByVal ModuleHandle As Integer, ByVal
ProcName As String) As Integer
Private Delegate Function dPassThruOpen(ByRef reserved As Integer,
ByRef DeviceId As Integer) As Integer
....
Dim ModuleHandle As Integer
Dim OpenMethodPointer As Integer
Dim temp As Integer
Dim ret As Long
Dim arg() As Object
Dim deviceId As Integer
ModuleHandle = LoadLibrary(myInstance.dllpath)
OpenMethodPointer = GetProcAddress(ModuleHandle, "PassThruOpen")
temp = 0
arg = New Object() {temp, deviceId}
ret = Marshal.GetDelegateForFunctionPointer(OpenMethodPointer,GetType(dPassThruOpen)).DynamicInvoke(arg)
ke(arg)
......
The above gets a valid ModuleHandle. A Valid OpenMethodPointer. The call to DynamicInvoke succeeds
and the ret provided makes sense (as it would have come from the DLL). However, the deviceId is not
filled in. What am I doing wrong?