Groups | Blog | Home
all groups > dotnet interop > october 2004 >

dotnet interop : DllImport, how to dinamically assing the DLL path?


Luis Fajardo
10/20/2004 12:51:04 PM
I don't want to put the .DLL in a known OS path folder, I'll like to define
or load the .DLL from an specific location at runtime. How should I do it?


James
10/20/2004 1:01:44 PM
You can always put the dll in the same folder as your
executable or referencing assembly. I have seen articles
on this around the net but can't find one right now.

[quoted text, click to view]
Luis Fajardo
10/20/2004 1:09:09 PM
James, thanks for your answer. What if the assembly is on the GAC? I'm
dealing with versioning issues, that's why I need to know where to locate the
..DLL. I need to be able to run two versions side by side, that means 2
assemblies on the GAC, and 2 .DLL, each set with different version levels.

Thanks



[quoted text, click to view]
James
10/20/2004 1:27:57 PM
To make sure I understand: You'll have 2 .NET assemblies
and two legacy Dlls. You want each .NET assembly to
reference a specific version of the legacy Dll.

If this is the case then the trouble is with the way
Windows loads Dlls - there are no provisions for choosing
which version you want your .NET assemblies to load. My
*guess* is that you may have to avoid using the DllImport
attribute and load them manually. The Win32 API *might*
give you the flexibility to do this, but this is way out
of my league.


[quoted text, click to view]
William DePalo [MVP VC++]
10/20/2004 4:11:49 PM
[quoted text, click to view]

This is just thinking out loud, though, as I have never tried it but ...

On very recent platforms (2K+3, XP/SP1) SetDllDirectory() might come in
handy. I'm not sure if it has a .Net equivalent or if you'd need to use
P/Invoke.

Regards,
Will

Robert Jordan
10/21/2004 1:24:57 AM
Hi Luis,

[quoted text, click to view]

http://www.codeproject.com/csharp/dyninvok.asp

bye
AddThis Social Bookmark Button