From VB (.net 2003), how do I call into a winapi dll in a different
directory,
1. without changing current dir
2. without adding the dll's dir to the path environment variable
3. without specifying the path at compile time
My current code is like this:
Private Declare Function MyFunc Lib "myfile.dll" (ByVal arg1 As String,
ByVal arg2 As String) As Short
But I have also tested this:
<DllImport("myfile.dll", EntryPoint:="MyFunc", SetLastError:=True,
CharSet:=CharSet.Ansi, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> Private Function MyFunc(ByVal
arg1 As String, ByVal arg2 As String) As Short
The problem is that the string "myfile.dll" in both cases must be specified
at compile time, and the directory isn't known at that time.
The LoadLibrary function can load winapi dlls in other dirs by simply
specifying a path before the dll file name, is it possible to do that in
.net at run time?
Mattias Sjögren - 04 May 2006 21:46 GMT
>The LoadLibrary function can load winapi dlls in other dirs by simply
>specifying a path before the dll file name, is it possible to do that in
>.net at run time?
You can call LoadLibrary yourself and specify the full path before
calling the DllImport function.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Anonymous - 05 May 2006 11:51 GMT
Thanks for your answer.
How easy is it to call LoadLibrary from vb? Do I get any automatic
marshalling of variables, or do I have to start fiddling with the stack?
If I instead uses the method "change directory before the call", can I
be sure of the binding always is perfomed when entering the callee
function? I guess it can depend on the JIT?
>>The LoadLibrary function can load winapi dlls in other dirs by simply
>>specifying a path before the dll file name, is it possible to do that in
[quoted text clipped - 4 lines]
>
> Mattias