Check-in [57ea797fa4]

Not logged in
Overview
SHA1 Hash:57ea797fa44d1f8c1fe8c1dd639aeffc744bc73c
Date: 2015-05-05 06:54:57
User: kinaba
Comment:Correct fix for std file handle closing issue.
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes
hide diffs side-by-side diffs patch

Modified src/dllmain.d from [9533046d0b42b4c6] to [1df1b32171114527].

1 1 import core.sys.windows.dll; 2 2 import core.sys.windows.windows; 3 +import std.stdio; 3 4 4 5 //---------------------------------------------------------------- 5 6 // おきまりのDLL初期化ルーチン 6 7 //---------------------------------------------------------------- 7 8 8 9 extern (Windows) 9 10 BOOL DllMain( HINSTANCE inst, ULONG reason, void* reserved ) ................................................................................ 11 12 switch( reason ) 12 13 { 13 14 case DLL_PROCESS_ATTACH: 14 15 dll_process_attach( inst, true ); 15 16 break; 16 17 17 18 case DLL_PROCESS_DETACH: 19 + _fcloseallp = null; // Do not close stdin/out/errs!!! 18 20 dll_process_detach( inst, true ); 19 21 break; 20 22 21 23 case DLL_THREAD_ATTACH: 22 24 dll_thread_attach( true, true ); 23 25 break; 24 26 ................................................................................ 26 28 dll_thread_detach( true, true ); 27 29 break; 28 30 29 31 default: 30 32 } 31 33 return true; 32 34 } 33 - 34 -/* 35 -// Hack! 36 -// 37 -// _acrtused_dllが勝手に終了時に標準入出力ハンドルを 38 -// 閉じちゃって困るので、その辺りだけは閉じないような 39 -// CloseHandleを突っ込んで回避。 40 -// 41 -// dmd v0.99 では動いていたのだけど最近のだとこれを入れると 42 -// 至る所でクラッシュするので考え直す必要がある。 43 -// TODO: bug report. 44 - 45 -extern(Windows) 46 -{ 47 - private alias BOOL function(HANDLE) ClHnT; 48 - private ClHnT Real_CloseHandle; 49 - private HANDLE stdin; 50 - private HANDLE stdout; 51 - private HANDLE stderr; 52 - 53 - BOOL CloseHandle( HANDLE h ) 54 - { 55 - if( h==stdin ) return TRUE; 56 - if( h==stdout ) return TRUE; 57 - if( h==stderr ) return TRUE; 58 - return Real_CloseHandle(h); 59 - } 60 -} 61 - 62 -static this() 63 -{ 64 - Real_CloseHandle = cast(ClHnT) 65 - GetProcAddress( GetModuleHandleA("kernel32.dll"), "CloseHandle" ); 66 - stdin = GetStdHandle(STD_INPUT_HANDLE ); 67 - stdout = GetStdHandle(STD_OUTPUT_HANDLE); 68 - stderr = GetStdHandle(STD_ERROR_HANDLE ); 69 -} 70 -*/

Modified src/testexe.d from [cc2ab2b91c87057b] to [e4521a091f44ac97].

3 3 import std.string; 4 4 import core.runtime; 5 5 6 6 alias extern(Windows) int function( HWND a, immutable char* b, char* c, DWORD d ) CmdFuncT; 7 7 8 8 void main() 9 9 { 10 - HINSTANCE h = cast(HINSTANCE) Runtime.loadLibrary("QBga32.DLL"); 11 10 for(;;) { 12 11 write("> "); 13 12 string s = readln(); 14 13 if(s.length > 0) { 14 + HINSTANCE h = cast(HINSTANCE) Runtime.loadLibrary("QBga32.DLL"); 15 15 CmdFuncT Bga = cast(CmdFuncT)GetProcAddress(h, "Bga"); 16 16 int r = Bga(NULL, s.toStringz(), null, 0); 17 + Runtime.unloadLibrary(h); 17 18 writeln("Return: ", r); 18 19 } 19 20 } 20 - Runtime.unloadLibrary(h); 21 21 }