Changeset 1476 for trunk/docsrc/dll.dd
- Timestamp:
- 04/01/10 16:55:46 (2 years ago)
- Files:
-
- trunk/docsrc/dll.dd (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docsrc/dll.dd
r989 r1476 35 35 36 36 -------------------------------- 37 import core.runtime;38 37 import std.c.windows.windows; 39 HINSTANCE g_hInst; 38 import core.dll_helper; 39 40 __gshared HINSTANCE g_hInst; 40 41 41 42 extern (Windows) 42 BOOL $(B DllMain)(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)43 BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) 43 44 { 44 45 switch (ulReason) 45 46 { 46 47 case DLL_PROCESS_ATTACH: 47 Runtime.initialize(); 48 g_hInst = hInstance; 49 dll_process_attach( hInstance, true ); 48 50 break; 49 51 50 52 case DLL_PROCESS_DETACH: 51 Runtime.terminate();53 dll_process_detach( hInstance, true ); 52 54 break; 53 55 54 56 case DLL_THREAD_ATTACH: 57 dll_thread_attach( true, true ); 58 break; 59 55 60 case DLL_THREAD_DETACH: 56 // Multiple threads not supported yet57 return false;61 dll_thread_detach( true, true ); 62 break; 58 63 } 59 g_hInst=hInstance;60 64 return true; 61 65 } 66 62 67 ------------------------------- 63 68 64 69 $(P Notes:) 65 70 $(UL 71 $(LI DllMain simply forwards to the appropriate helper functions. These setup 72 the runtime, create thread objects for interaction with the garbage collector 73 and initialize thread local storage data.) 74 $(LI The DLL does not share its runtime or memory with other DLLs.) 75 $(LI The first boolean argument to the dll-helper functions specify whether all threads 76 should be controlled by the garbage collector. You might need more control over 77 this behaviour if there are threads in the process that must not be suspended. 78 In this case pass false to disable the automatic handling of all threads.) 66 79 $(LI The presence of $(TT DllMain()) is recognized by the compiler 67 80 causing it to emit a reference to … … 80 93 EXETYPE NT 81 94 CODE PRELOAD DISCARDABLE 82 DATA PRELOAD SINGLE95 DATA WRITE 83 96 84 97 EXPORTS … … 97 110 ) 98 111 99 <h4>mydll 2.d:</h4>112 <h4>mydll.d:</h4> 100 113 ------------------------------- 101 114 module mydll; 115 import std.c.stdio; 102 116 export void dllprint() { printf("hello dll world\n"); } 103 117 ------------------------------- … … 124 138 125 139 $(CONSOLE 126 C:>dmd -ofmydll.dll mydll2.d dll.d mydll.def 127 C:>implib/system mydll.lib mydll.dll 140 C:>dmd -ofmydll.dll -L/IMPLIB mydll.d dll.d mydll.def 128 141 C:> 129 142 ) … … 144 157 ------------------------------- 145 158 146 $(P Create a clone of mydll2.dthat doesn't have the function bodies:)147 148 <h4>mydll.d :</h4>159 $(P Create an interface file mydll.di that doesn't have the function bodies:) 160 161 <h4>mydll.di:</h4> 149 162 ------------------------------- 150 163 export void dllprint(); … … 189 202 it. Establish a protocol where the caller informs the D DLL when it is 190 203 safe to free the data.) 204 205 $(LI Notify the GC about external references to a memory block by 206 calling GC.addRange.) 191 207 192 208 $(LI Use operating system primitives like VirtualAlloc() to allocate
