D
Dragon
Hello,
I was translating some sample from MSDN from C to VB .NET, and got the
following:
~
Private Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As
IntPtr, <MarshalAs(UnmanagedType.LPStr)> ByVal lpProcName As String) As
<MarshalAs(UnmanagedType.FunctionPtr)> DLLGETVERSIONPROC
Private Delegate Function DLLGETVERSIONPROC(ByRef dvi As DLLVERSIONINFO) As
Integer
Private Function GetDllVersion(ByVal lpszDllName As String) As Integer
Dim hinstDll As IntPtr
Dim dwVersion As Integer = 0
hinstDll = LoadLibrary(lpszDllName)
If hinstDll.ToInt32 <> 0 Then
Dim pDllGetVersion As DLLGETVERSIONPROC
pDllGetVersion = GetProcAddress(hinstDll, "DllGetVersion")
If Not pDllGetVersion Is Nothing Then
Dim dvi As DLLVERSIONINFO
Dim hr As Integer
dvi.cbSize = Marshal.SizeOf(dvi)
hr = pDllGetVersion.Invoke(dvi)
If SUCCEEDED(hr) Then
dwVersion = PACKVERSION(dvi.dwMajorVersion, dvi.dwMinorVersion)
End If
End If
FreeLibrary(hinstDll)
End If
Return dwVersion
End Function
~
When I call this function, an error box pops out:
An unhandled exception of type 'System.ArgumentException' occurred in
WinApp.exe
Additional information: äÅÌÅÇÁÔ ÎÅ ÓÏÚÄÁÌ ÕËÁÚÁÔÅÌØ ÎÁ ÆÕÎËÃÉÀ.
(Translation: Delegate haven't created the function pointer.)
If I declare GetProcAddress as Integer it returns normal value, so it's
probably a marshalling problem.
Can I do something to get a delegate value?
Thanks in advance.
I was translating some sample from MSDN from C to VB .NET, and got the
following:
~
Private Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As
IntPtr, <MarshalAs(UnmanagedType.LPStr)> ByVal lpProcName As String) As
<MarshalAs(UnmanagedType.FunctionPtr)> DLLGETVERSIONPROC
Private Delegate Function DLLGETVERSIONPROC(ByRef dvi As DLLVERSIONINFO) As
Integer
Private Function GetDllVersion(ByVal lpszDllName As String) As Integer
Dim hinstDll As IntPtr
Dim dwVersion As Integer = 0
hinstDll = LoadLibrary(lpszDllName)
If hinstDll.ToInt32 <> 0 Then
Dim pDllGetVersion As DLLGETVERSIONPROC
pDllGetVersion = GetProcAddress(hinstDll, "DllGetVersion")
If Not pDllGetVersion Is Nothing Then
Dim dvi As DLLVERSIONINFO
Dim hr As Integer
dvi.cbSize = Marshal.SizeOf(dvi)
hr = pDllGetVersion.Invoke(dvi)
If SUCCEEDED(hr) Then
dwVersion = PACKVERSION(dvi.dwMajorVersion, dvi.dwMinorVersion)
End If
End If
FreeLibrary(hinstDll)
End If
Return dwVersion
End Function
~
When I call this function, an error box pops out:
An unhandled exception of type 'System.ArgumentException' occurred in
WinApp.exe
Additional information: äÅÌÅÇÁÔ ÎÅ ÓÏÚÄÁÌ ÕËÁÚÁÔÅÌØ ÎÁ ÆÕÎËÃÉÀ.
(Translation: Delegate haven't created the function pointer.)
If I declare GetProcAddress as Integer it returns normal value, so it's
probably a marshalling problem.
Can I do something to get a delegate value?
Thanks in advance.