DLL unloading itself

As I understand it, it CAN be done and is MEANT to be done sometimes (for example in case of dll injection by CreateRemoteThread and other methods). So, FreeLibraryAndExitThread(hModule, 0) will do precisely that. On the other hand, calling FreeLibrary(hModule) will not do here – from MSDN: “If they were to call FreeLibrary and ExitThread … Read more

Loading a dll from a dll?

After all the debate that went on in the comments, I think that it’s better to summarize my positions in a “real” answer. First of all, it’s still not clear why you need to load a dll in DllMain with LoadLibrary. This is definitely a bad idea, since your DllMain is running inside another call … Read more

C++ How to compile dll in a .exe

In order to achieve that you will need static linking. This requires that all your libraries (and the libraries they depend upon recursively) need to be available as static libraries. Be aware that the size of your executable will be large, as it will carry all the code from those static libraries. This is why … Read more

Calling C++ dll from Java

You need to include the Java class name and path in your native code, for example if your native method was declared in Java as: public class NativeCode { public static native boolean CreateSession(); } and the class path was (for example) com.example.NativeCode you would declare your method in native as follows: extern “C” JNIEXPORT … Read more