How To Use LoadLibrary()/GetProcAddress()
Apr 3, 2011The 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?