Show
Ignore:
Timestamp:
04/01/10 16:55:46 (2 years ago)
Author:
walter
Message:

lots of minor edits

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docsrc/dll.dd

    r989 r1476  
    3535 
    3636-------------------------------- 
    37 import core.runtime; 
    3837import std.c.windows.windows; 
    39 HINSTANCE g_hInst; 
     38import core.dll_helper; 
     39 
     40__gshared HINSTANCE g_hInst; 
    4041 
    4142extern (Windows) 
    42 BOOL $(B DllMain)(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) 
     43BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) 
    4344{ 
    4445    switch (ulReason) 
    4546    { 
    4647    case DLL_PROCESS_ATTACH: 
    47         Runtime.initialize(); 
     48        g_hInst = hInstance; 
     49        dll_process_attach( hInstance, true ); 
    4850        break; 
    4951 
    5052    case DLL_PROCESS_DETACH: 
    51         Runtime.terminate(); 
     53        dll_process_detach( hInstance, true ); 
    5254        break; 
    5355 
    5456    case DLL_THREAD_ATTACH: 
     57        dll_thread_attach( true, true ); 
     58        break; 
     59 
    5560    case DLL_THREAD_DETACH: 
    56         // Multiple threads not supported yet 
    57         return false
     61        dll_thread_detach( true, true ); 
     62        break
    5863    } 
    59     g_hInst=hInstance; 
    6064    return true; 
    6165} 
     66 
    6267------------------------------- 
    6368 
    6469    $(P Notes:) 
    6570    $(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.) 
    6679    $(LI The presence of $(TT DllMain()) is recognized by the compiler 
    6780        causing it to emit a reference to 
     
    8093EXETYPE     NT 
    8194CODE            PRELOAD DISCARDABLE 
    82 DATA            PRELOAD SINGL
     95DATA            WRIT
    8396 
    8497EXPORTS 
     
    97110    ) 
    98111 
    99     <h4>mydll2.d:</h4> 
     112    <h4>mydll.d:</h4> 
    100113------------------------------- 
    101114module mydll; 
     115import std.c.stdio; 
    102116export void dllprint() { printf("hello dll world\n"); } 
    103117------------------------------- 
     
    124138 
    125139$(CONSOLE 
    126 C:>dmd -ofmydll.dll mydll2.d dll.d mydll.def 
    127 C:>implib/system mydll.lib mydll.dll 
     140C:>dmd -ofmydll.dll -L/IMPLIB mydll.d dll.d mydll.def 
    128141C:> 
    129142) 
     
    144157------------------------------- 
    145158 
    146     $(P Create a clone of mydll2.d that 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> 
    149162------------------------------- 
    150163export void dllprint(); 
     
    189202    it. Establish a protocol where the caller informs the D DLL when it is 
    190203    safe to free the data.) 
     204 
     205    $(LI Notify the GC about external references to a memory block by 
     206    calling GC.addRange.) 
    191207 
    192208    $(LI Use operating system primitives like VirtualAlloc() to allocate