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
如果DLLImport没有指定任何路径,它应该在应用程序文件夹中查找。
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
Just specify dll name without path. As below:
[DllImport("Dllname.dll")]
static extern void Foo();
And it would be searched in app folder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.