root/branches/bud/sss/dsssdll.d

Revision 86, 2.1 kB (checked in by Gregor, 2 years ago)

Changed everything to MIT license.

Line 
1 /**
2  * DSSS stubbed DLLMain (used to build any library as a DLL)
3  *
4  * Authors:
5  *  Gregor Richards
6  *
7  * License:
8  *  Copyright (c) 2006  Gregor Richards
9  * 
10  *  Permission is hereby granted, free of charge, to any person obtaining a
11  *  copy of this software and associated documentation files (the "Software"),
12  *  to deal in the Software without restriction, including without limitation
13  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  *  and/or sell copies of the Software, and to permit persons to whom the
15  *  Software is furnished to do so, subject to the following conditions:
16  * 
17  *  The above copyright notice and this permission notice shall be included in
18  *  all copies or substantial portions of the Software.
19  * 
20  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  *  DEALINGS IN THE SOFTWARE.
27  */
28
29 version (DSSSDLL) {
30     import std.c.stdio;
31     import std.c.stdlib;
32     import std.string;
33     import std.c.windows.windows;
34     import std.gc;
35    
36     HINSTANCE   g_hInst;
37    
38     extern (C)
39     {
40     void _minit();
41     void _moduleCtor();
42     void _moduleDtor();
43     }
44    
45     extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
46     {
47         switch (ulReason)
48         {
49             case DLL_PROCESS_DETACH:
50                 std.c.stdio._fcloseallp = null;
51                 break;
52         }
53         g_hInst = hInstance;
54         return true;
55     }
56    
57     void DLL_Initialize(void* gc)
58     {
59         std.gc.setGCHandle(gc);
60         _minit();
61         _moduleCtor();
62     }
63    
64     void DLL_Terminate()
65     {
66         _moduleDtor();
67         std.gc.endGCHandle();
68     }
69    
70     version (build) {
71         pragma(link, "kernel32");
72     }
73 }
Note: See TracBrowser for help on using the browser.