i can call (DLLImport) Win32 .DLL file from a constant specified path in C#.NET. but if i want to load it from my aplications folder (executavle file path) , what shoud i do? the DLLImport Attribute doesn't allow to specify a variable path. plz help me. tnx
Asked
Active
Viewed 1,684 times
3 Answers
1
If you DLLImport without specifying any path it should look in the application folder.

Felice Pollano
- 32,832
- 9
- 75
- 115
1
Use SetDllDirectory Function to specify a path of your choice.
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
More on MSDN: http://msdn.microsoft.com/en-us/library/ms686203%28VS.85%29.aspx
Check earlier post on stackoverflow: Specify the search path for DllImport in .NET
0
Just specify dll name without path. As below:
[DllImport("Dllname.dll")]
static extern void Foo();
And it would be searched in app folder.

Anton Semenov
- 6,227
- 5
- 41
- 69