A
A
Anton2016-01-16 21:24:59
C++ / C#
Anton, 2016-01-16 21:24:59

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:
9e0b7df3ed054002b63d11bd070ea2c1.png
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

1 answer(s)
P
Peter, 2016-01-16
@petermzg

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 question

Ask a Question

731 491 924 answers to any question