Skip to content

Instantly share code, notes, and snippets.

Created November 20, 2013 23:06
Show Gist options
  • Save anonymous/7572848 to your computer and use it in GitHub Desktop.
Save anonymous/7572848 to your computer and use it in GitHub Desktop.
BOOL WINAPI DllMain(HINSTANCE module_handle, DWORD reason_for_call, LPVOID reserved)
{
if (reason_for_call == DLL_PROCESS_ATTACH) // Self-explanatory
{
DisableThreadLibraryCalls(module_handle); // Disable DllMain calls for DLL_THREAD_*
if (reserved == NULL) // Dynamic load
{
foobar_meow(); // Initialize your stuff or whatever
// Return FALSE if you don't want your module to be dynamically loaded
}
else // Static load
{
// Return FALSE if you don't want your module to be statically loaded
return FALSE;
}
}
if (reason_for_call == DLL_PROCESS_DETACH) // Self-explanatory
{
if (reserved == NULL) // Either loading the DLL has failed or FreeLibrary was called
{
// Cleanup
}
else // Process is terminating
{
// Cleanup
}
}
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment