Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / May 2006

Tip: Looking for answers? Try searching our database.

call dll in another directory

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Anonymous - 04 May 2006 17:46 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.