Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #706 from adamdruppe/windows_dll
Browse files Browse the repository at this point in the history
boilerplate mixin
  • Loading branch information
yebblies committed Sep 10, 2014
2 parents 7a18c79 + b2e3ca6 commit 5566f0f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/core/sys/windows/dll.d
Expand Up @@ -460,4 +460,39 @@ public:
}
return true;
}

/// A simple mixin to provide a $(D DllMain) which calls the necessary
/// runtime initialization and termination functions automatically.
///
/// Instead of writing a custom $(D DllMain), simply write:
///
/// ---
/// mixin SimpleDllMain;
/// ---
mixin template SimpleDllMain()
{
import core.sys.windows.windows : HINSTANCE;

extern(Windows)
bool DllMain(HINSTANCE hInstance, uint ulReason, void* reserved)
{
import core.sys.windows.windows;
switch(ulReason)
{
default: assert(0);
case DLL_PROCESS_ATTACH:
return dll_process_attach( hInstance, true );

case DLL_PROCESS_DETACH:
dll_process_detach( hInstance, true );
return true;

case DLL_THREAD_ATTACH:
return dll_thread_attach( true, true );

case DLL_THREAD_DETACH:
return dll_thread_detach( true, true );
}
}
}
}

0 comments on commit 5566f0f

Please sign in to comment.