简体   繁体   中英

How can I call mixed mode C# dll from Delphi using BTMemoryModule?

I have a DLL written in C# that uses Robert Giesecke's UnmanagedExports library and exports functions with [DllExport] .

I can load it fine with LoadLibrary , and call its exported functions. When I tried to load it into memory using BTMemoryModule , the call of entry point (DllMain - DLL_PROCESS_ATTACH) TDllEntryProc (in function BTMemoryLoadLibary ) returns false. How can I load such a DLL using BTMemoryModule .

Loading DLLs from memory is not unsupported. Any code that does this is using unsupported hacks to do so. The system provides LoadLibrary , LoadLibraryEx etc. to perform this task, and they require the DLL to be present on disk.

Your DLL is a mixed mode .net assembly, and it requires special treatment by the loader. The system loader, as invoked by calls to LoadLibrary , LoadLibraryEx etc. knows how to perform the actions needed to load a mixed mode .net assembly. The BTMemoryModule code does not perform these special actions.

If you are going to be able to load such a module from memory, you will need to either find a library that supports such modules, or write your own loader code. Frankly, I doubt that such a library exists. More realistically you should load the DLL from disk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM