When importing a dll Windows has a resolution process of Assembly, it checks in some places like Windows System, Windows System32, Windows Syswow64, in the global cache, or in the application directory. I can’t tell you the exact algorithm or the precedence of each directory.
For sure you will find libraries (Wrappers) of the type NativeMethods
through the internet, it is common to do this.
Behold:
https://referencesource.microsoft.com/#Presentationframework/src/Framework/System/windows/Standard/Nativemethods.Cs
The library of this example is mixed.
And another detail, the app only loads the dlls you use, to see this test:
[DllImport("fake.dll")]
static extern void FuncaoFake();
If you do not call the function the application shows no error.
But call FuncaoFake()
it shows the following error:
System.Dllnotfoundexception: 'Unable to load the DLL 'fake.dll': Could not find the specified module. (Exception of HRESULT: 0x8007007E)'
Remembering that the abusive use of platform invoke
It’s a bit of a departure from the philosophy of managed code. Native function calls need some extra instructions to be invoked, Microsoft recommends few calls passing enough data instead of many calls passing little data per call, sorry I did not find the documentation link on this.
If your application depends intensely on this type of call it is more recommended to write in C++
.
Good would be if there was a tool like Dllwrapperbuilder, you play the dll and it gives you a file. Cs with the Imports.
– user178974