1 /**
2  * Copyright: Copyright Auburn Sounds 2015-2016.
3  * License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
4  * Authors:   Guillaume Piolat
5  */
6 module dplug.client.dllmain;
7 
8 // Dynamic libraries entry point.
9 // Basically only needed on Windows, on OSX we have other entry points.
10 
11 version = doNotUseRuntime;
12 
13 version(Windows)
14 {
15     version(doNotUseRuntime)
16     {
17         template DLLEntryPoint()
18         {
19             const char[] DLLEntryPoint = q{
20                 import std.c.windows.windows;
21                 import core.sys.windows.dll;
22                 extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
23                 {
24                     return true;
25                 }
26             };
27         }
28     }
29     else
30     {
31         template DLLEntryPoint()
32         {
33             const char[] DLLEntryPoint = q{
34                 import std.c.windows.windows;
35                 import core.sys.windows.dll;
36 
37                 extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
38                 {
39                     switch (ulReason)
40                     {
41                         case DLL_PROCESS_ATTACH:
42                             dll_process_attach(hInstance, false);
43                             break;
44 
45                         case DLL_PROCESS_DETACH:
46                             dll_process_detach(hInstance, true);
47                             break;
48 
49                         case DLL_THREAD_ATTACH:
50                             dll_thread_attach(false, true);
51                             break;
52 
53                         case DLL_THREAD_DETACH:
54                             dll_thread_detach(false, true); 
55                             break;
56 
57                         default:
58                             break;
59                     }
60                     return true;
61                 }
62             };
63         }
64     }
65 }
66 else
67 {
68     template DLLEntryPoint()
69     {
70         const char[] DLLEntryPoint = ``;
71     }
72 }
73