Question

No matter how weird it sounds, I need it O_o Well, the another solution, if it possible to load native DLL as byte array into RAM, but call function from there without DllImport >_<

Kinda this way:

byte[] dll_data = File.RealAllBytes("native.dll"); //this is just example, in real architecture bytes comes from another source and should never be stored on HDD
//uhh... ohh... do something to call exported function named "WeirdNativeFunction"
Était-ce utile?

La solution

You'd need to call the appropriate methods to load the native DLL into the calling process. The MemoryModule project on GitHub provides a (native) API for handling this, which you could use from a C++/CLI project.

Once you had the native.dll loaded into the process, you could use P/Invoke to call GetProcAddress to get a handle to the "WeirdNativeFunction", and Marshal.GetDelegateForFunctionPointer to convert it to a managed delegate, which you could then call.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top