How To Use LoadLibrary()/GetProcAddress()

Apr 3, 2011

The following code works great to interface *.dll that I built in Ada from VB.NET (2008) ...

Private Declare Function TestDelegate Lib "C:ABC.dll" Alias "Test" _
(ByVal A As Single, _
ByVal B As Integer, _

[code]....

... where TestType is a struct. The only problem I have with this is that the *.dll and its path has to be hard coded.

So I started looking at using LoadLibrary() and GetProcAddress(). I figured out the following interfaces ...

<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Function LoadLibrary(<[In](), MarshalAs(UnmanagedType.LPTStr)> ByVal lpFileName As String) As IntPtr
End Function

[code]....

I check for IntPtr.Zero to make sure this all worked but now the question is how can I actually use the lFunctionHandle to call Test()?

I'm also curious what the difference is between the <DllImport("kernel32.dll" ... and something like Private Declare Function ABC Lib "kernel32" (...) As XYZ to interface a *.dll? whether it is necessary to call FreeLibrary() or whether VB will handle freeing up the memory?

View 6 Replies


ADVERTISEMENT

Make A DLL Function That Works With GetProcAddress?

May 29, 2011

I recently created a Class just for dynamically invoking API's and it works with system libraries (kernel32, user32, etc.) Here is the code:

NotInheritable Class DynamicAPI
#Region "API"
<Runtime.InteropServices.DllImport("kernel32.dll", SetLastError:=True)> Private Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr

[code]....

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved