Questions tagged [dllmain]

In a Windows DLL, the DllMain function is automatically run when the DLL is loaded, just before it is unloaded, and whenever a process thread is started or exits cleanly.

In a Windows DLL, the DllMain function is automatically run when the DLL is loaded, just before it is unloaded (provided the process either explicitly unloads the DLL or exits cleanly) and whenever a process thread is started or exits cleanly.

DllMain is a placeholder for the function name defined by the library. The actual name must be specified when building the DLL. Recommended practice, where possible, is for a library to provide an explicit initialization function for the caller to use rather than using DllMain.

The DllMain function must be used cautiously, as only certain Win32 API functions are safe to call from DllMain. In particular, it must not call API functions that are not in kernel32.dll and it must not cause another DLL to be loaded either directly or indirectly. Communication with other threads or processes is also prohibited.

It is known to be safe to create synchronization objects and to use TLS (Thread Local Storage) in DllMain, so these are the most common uses. Another common use is to allocate per-thread objects. In C++, the runtime library will typically create global and static objects for your DLL using DllMain.

48 questions
-2
votes
1 answer

Query Dll layout information

I want to query the following information from a DLL in memory: Exact address of entry point (DllMain?!) Address and size of the code section of the Dll Addresses of entry points of each EXPORTED function I used GetModuleInformation() from the…
user2252343
  • 95
  • 2
  • 7
-3
votes
1 answer

Dllmain function is not being called

I searched here but none of these questions helped me so yeah I'll explain: My Dllmain function is not being called when it attaches to a process (rundll32.exe) in visual studio project settings I changed it to attach to rundll32.exe it was supposed…
SadLandscape
  • 75
  • 1
  • 8
-4
votes
1 answer

DllMain entry point DLL_PROCESS_DETACH

I have a c++ dll, called from a c# process... [DllImport(@"My.dll", EntryPoint = "Function1", CallingConvention = CallingConvention.Cdecl)] public static extern bool MyFunction(int id1, int id2, [MarshalAsAttribute(UnmanagedType.LPWStr)]…
TEDSON
  • 191
  • 2
  • 13
1 2 3
4