Catch DllNotFoundException P/Invoke

: DllImport?

, , Windows- NT- Windows. Vista-series, DLL ( DllImport), . , DllImport DllNotFoundException , Windows, DLL.

// DllNotFoundExceptions? "" .

+3
source share
2 answers

I think you should go the "traditional" way with win32 LoadLibrary / GetProcAddress / FreeLibrary and a delegate (just like you do with callback functions).

http://msdn.microsoft.com/en-us/library/d186xcf0.aspx could be the starting point ...

This should help you:

[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr LoadLibrary(string lpFileName);

[DllImport("kernel32.dll", SetLastError=true)]
static extern bool FreeLibrary(IntPtr hModule);

[DllImport("kernel32.dll", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=true)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);

Then you declare the delegate with the correct signature of the exported one that is being called, and use Marshal.GetDelegateForFunctionPointer () to create it from the function pointer that you received from GetProcAddress .

+2
source

- ++/CLI, DLL Windows LoadLibrary DLL.

+1

Source: https://habr.com/ru/post/1722089/


All Articles