1 module selfscript.windll; 2 3 enum winDllDefFileContent = " 4 LIBRARY MYDLL 5 DESCRIPTION 'MyDll demonstration DLL' 6 EXETYPE NT 7 CODE PRELOAD DISCARDABLE 8 DATA PRELOAD MULTIPLE 9 "; 10 11 enum winDllFileContent = " 12 // copied and modified from http://wiki.dlang.org/Win32_DLLs_in_D 13 module dllmainbody; 14 15 import core.runtime; 16 import core.stdc.stdio; 17 import core.stdc.stdlib; 18 import std.string; 19 import core.sys.windows.windows; 20 21 HINSTANCE g_hInst; 22 23 extern (C) 24 { 25 void gc_setProxy(void* p); 26 void gc_clrProxy(); 27 } 28 29 extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) 30 { 31 // disable auto fpclose actions. should be taken care of by the parent process 32 import std.stdio; 33 _fcloseallp = null; 34 switch (ulReason) 35 { 36 case DLL_PROCESS_ATTACH: 37 Runtime.initialize(); 38 break; 39 40 case DLL_PROCESS_DETACH: 41 Runtime.terminate(); 42 break; 43 44 case DLL_THREAD_ATTACH: 45 return false; 46 47 case DLL_THREAD_DETACH: 48 return false; 49 default: 50 } 51 g_hInst = hInstance; 52 return true; 53 } 54 55 extern (C) { 56 export void dllInitialize(void* gc) 57 { 58 gc_setProxy(gc); 59 } 60 61 export void dllTerminate() 62 { 63 gc_clrProxy(); 64 } 65 } 66 ";