Answer the question
In order to leave comments, you need to log in
How to solve the problem when using Properties.Settings in DllImport?
Hello!
If you write the path in DllImport like this: @"C:\path\library.dll"
Then everything is fine.
But if this piece is completely replaced with this: Properties.Settings.Default.dllPath
Then an error pops up:
I know that the @ symbol prohibits further formatting of the string (essentially a constant). Interested in how to fix it using Properties.Settings, or how to store paths of this kind in a different way, so as not to duplicate them in the code, but to pull them out of the config?
Answer the question
In order to leave comments, you need to log in
If you don't want to link statically, you can load it dynamically.
Example:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int MultiplyByTen(int numberToMultiply);
IntPtr pDll = NativeMethods.LoadLibrary(@"PathToYourDll.DLL");
IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "MultiplyByTen");
MultiplyByTen multiplyByTen = (MultiplyByTen)Marshal.GetDelegateForFunctionPointer(
pAddressOfFunctionToCall,
typeof(MultiplyByTen));
int theResult = multiplyByTen(10);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question