JasonMewes
asked on
Import unmanaged Dll to C# application
I need to import a dll built in unmanaged code, to my C# application. The dll is placed in the same place as the executable. Since I don't know where the user will choose to install the application, I need to define the path to the dll at runtime. How can this be done?
[DllImport("MyImport.dll", CharSet = CharSet.Ansi)] gives DllNotFoundEexception (Exception from HRESULT: 0x8007007E)
[DllImport(Application.Sta rtupPath + "\\MyImport.dll", CharSet = CharSet.Ansi)] gives build errror "An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type"
[DllImport("MyImport.dll",
[DllImport(Application.Sta
ASKER
Thanks for your answer. I have now found the cause of the error. The import dll couldnt find one of it's dependencies, which caused the error. So in fact the error message was misleading.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for JasonMewes's comment #a40004055
for the following reason:
The import dll couldnt find one of it's dependencies, which caused the error. So in fact the error message was misleading.
Accepted answer: 0 points for JasonMewes's comment #a40004055
for the following reason:
The import dll couldnt find one of it's dependencies, which caused the error. So in fact the error message was misleading.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If that is the case then the line:
[DllImport("MyImport.dll"
should find the dll, because searching the directory the exe is located in is one of the default locations the DllImport uses when it searches.
Check the dll is really in that folder and check the spelling (it should not be case sensitive).