If I specify only the name

[DllImport("example.dll", EntryPoint = "_foo@4")] private static extern int foo(); 

dll search is performed only in the system32 folder. I would like to connect dll'ku, located in the same folder with the program. How to do it?

Added.

If, without taking additional actions, simply put the dll in the program folder and do not put it in system32, an exception is caught:

System.DllNotFoundException: Unable to load dll "example.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E).

    1 answer 1

    DLL search algorithm may vary on different platforms and with different installations. Read more here: Dynamic-Link Library Search Order . But almost certainly, the folder in which the executable file is located is included in the viewed path. Therefore, it is worth making sure that you really put the DLL in the same place as the exe.