Differences From Artifact [1c734ac63ab48040]:
- File
src/qbga32.d
-
2015-05-05 06:49:05
- part of checkin
[9b639cf2d6]
on branch trunk
- Working version for update to 2.067.
The problem was __gshared. Replacing it with TLS fixed the issue. Remaining problem is that "hack.d"'s CloseHandle hack is not working anymore.
(user: kinaba) [annotate]
-
2015-05-05 06:49:05
- part of checkin
[9b639cf2d6]
on branch trunk
- Working version for update to 2.067.
To Artifact [55bc981232a3491c]:
- File
src/qbga32.d
- 2015-07-02 16:22:43 - part of checkin [9f9e8588d4] on branch trunk - 0.06: avoid crash when _Bga32.dll does not exist. (user: kinaba) [annotate]
1 import win32.windows; 1 import win32.windows;
2 import std.string; 2 import std.string;
3 import std.file; 3 import std.file;
> 4 import std.traits;
4 import util; 5 import util;
5 import windll; 6 import windll;
6 import bga_melter; 7 import bga_melter;
7 import qbga_gui; 8 import qbga_gui;
8 9
9 //---------------------------------------------------------------- 10 //----------------------------------------------------------------
10 // API転送処理 11 // API転送処理
11 //---------------------------------------------------------------- 12 //----------------------------------------------------------------
12 13
13 WinDLL g_orig_dll = null; 14 WinDLL g_orig_dll = null;
14 UINT WM_ARCEXTRACT; 15 UINT WM_ARCEXTRACT;
> 16 const ERROR_NO_BGA32DLL = 0x9000;
15 17
16 static this() 18 static this()
17 { 19 {
18 g_orig_dll = WinDLL.load( "_Bga32.DLL" ); 20 g_orig_dll = WinDLL.load( "_Bga32.DLL" );
19 WM_ARCEXTRACT = RegisterWindowMessage("wm_arcextract"); 21 WM_ARCEXTRACT = RegisterWindowMessage("wm_arcextract");
20 } 22 }
21 23
22 static ~this() 24 static ~this()
23 { 25 {
> 26 if(g_orig_dll)
24 g_orig_dll.close(); | 27 g_orig_dll.close();
25 } 28 }
26 29
27 template api(FnT) | 30 FnT api(FnT, int defaultR)(string name)
28 { 31 {
29 FnT api( string name ) | 32 FnT def = function(ParameterTypeTuple!(FnT) xs) {
30 { <
31 return g_orig_dll.get_api!(FnT)( name ); <
> 33 return cast(ReturnType!(FnT))defaultR;
32 } | 34 };
> 35 if(g_orig_dll is null) return def;
> 36 FnT f = g_orig_dll.get_api!(FnT)(name);
> 37 return f ? f : def;
33 } 38 }
34 39
35 //---------------------------------------------------------------- 40 //----------------------------------------------------------------
36 // 統合アーカイバAPI:転送 41 // 統合アーカイバAPI:転送
37 //---------------------------------------------------------------- 42 //----------------------------------------------------------------
38 43
39 extern(Windows) 44 extern(Windows)
40 { 45 {
41 int Bga( HWND a, immutable char* b, char* c, DWORD d ) 46 int Bga( HWND a, immutable char* b, char* c, DWORD d )
42 { 47 {
43 int r = Bga_impl( a, b.fromStringz() ); 48 int r = Bga_impl( a, b.fromStringz() );
44 if( r < 0 ) // このダミーDLLでは処理できないコマンドだった時 49 if( r < 0 ) // このダミーDLLでは処理できないコマンドだった時
45 return api!(typeof(&Bga))("Bga")(a,b,c,d); | 50 return api!(typeof(&Bga), ERROR_NO_BGA32DLL)("Bga")(a,b,
46 return r; 51 return r;
47 } 52 }
48 53
49 WORD QBgaGetVersion() 54 WORD QBgaGetVersion()
50 { 55 {
51 return 5; | 56 return 6;
52 } 57 }
53 58
54 WORD BgaGetVersion() 59 WORD BgaGetVersion()
55 { 60 {
56 return api!(typeof(&BgaGetVersion))("BgaGetVersion")(); | 61 return api!(typeof(&BgaGetVersion), 0)("BgaGetVersion")();
57 } 62 }
58 63
59 BOOL BgaGetRunning() 64 BOOL BgaGetRunning()
60 { 65 {
61 return api!(typeof(&BgaGetRunning))("BgaGetRunning")(); | 66 return api!(typeof(&BgaGetRunning), FALSE)("BgaGetRunning")();
62 } 67 }
63 68
64 BOOL BgaCheckArchive( char* a, int b ) 69 BOOL BgaCheckArchive( char* a, int b )
65 { 70 {
66 return api!(typeof(&BgaCheckArchive))("BgaCheckArchive")(a,b); | 71 return api!(typeof(&BgaCheckArchive), FALSE)("BgaCheckArchive")(
67 } 72 }
68 73
69 BOOL BgaConfigDialog( HWND a, char* b, int c ) 74 BOOL BgaConfigDialog( HWND a, char* b, int c )
70 { 75 {
71 return api!(typeof(&BgaConfigDialog))("BgaConfigDialog")(a,b,c); | 76 return api!(typeof(&BgaConfigDialog), ERROR_NO_BGA32DLL)("BgaCon
72 } 77 }
73 78
74 int BgaGetFileCount( char* a ) 79 int BgaGetFileCount( char* a )
75 { 80 {
76 return api!(typeof(&BgaGetFileCount))("BgaGetFileCount")(a); | 81 return api!(typeof(&BgaGetFileCount), -1)("BgaGetFileCount")(a);
77 } 82 }
78 83
79 BOOL BgaQueryFunctionList( int a ) 84 BOOL BgaQueryFunctionList( int a )
80 { 85 {
81 return api!(typeof(&BgaQueryFunctionList))("BgaQueryFunctionList | 86 return api!(typeof(&BgaQueryFunctionList), FALSE)("BgaQueryFunct
82 } 87 }
83 88
84 alias void* HARC; 89 alias void* HARC;
85 HARC BgaOpenArchive( HWND a, char* b, DWORD c ) 90 HARC BgaOpenArchive( HWND a, char* b, DWORD c )
86 { 91 {
87 return api!(typeof(&BgaOpenArchive))("BgaOpenArchive")(a,b,c); | 92 return api!(typeof(&BgaOpenArchive), 0)("BgaOpenArchive")(a,b,c)
88 } 93 }
89 94
90 int BgaCloseArchive( HARC a ) 95 int BgaCloseArchive( HARC a )
91 { 96 {
92 return api!(typeof(&BgaCloseArchive))("BgaCloseArchive")(a); | 97 return api!(typeof(&BgaCloseArchive), 0)("BgaCloseArchive")(a);
93 } 98 }
94 99
95 alias void* LPINDIVIDUALINFO; 100 alias void* LPINDIVIDUALINFO;
96 int BgaFindFirst( HARC a, char* b, LPINDIVIDUALINFO c ) 101 int BgaFindFirst( HARC a, char* b, LPINDIVIDUALINFO c )
97 { 102 {
98 return api!(typeof(&BgaFindFirst))("BgaFindFirst")(a,b,c); | 103 return api!(typeof(&BgaFindFirst), -1)("BgaFindFirst")(a,b,c);
99 } 104 }
100 105
101 int BgaFindNext( HARC a, LPINDIVIDUALINFO b ) 106 int BgaFindNext( HARC a, LPINDIVIDUALINFO b )
102 { 107 {
103 return api!(typeof(&BgaFindNext))("BgaFindNext")(a,b); | 108 return api!(typeof(&BgaFindNext), -1)("BgaFindNext")(a,b);
104 } 109 }
105 110
106 DWORD BgaGetArcOriginalSize( HARC a ) 111 DWORD BgaGetArcOriginalSize( HARC a )
107 { 112 {
108 return api!(typeof(&BgaGetArcOriginalSize))("BgaGetArcOriginalSi | 113 return api!(typeof(&BgaGetArcOriginalSize), -1)("BgaGetArcOrigin
109 } 114 }
110 115
111 DWORD BgaGetArcCompressedSize( HARC a ) 116 DWORD BgaGetArcCompressedSize( HARC a )
112 { 117 {
113 return api!(typeof(&BgaGetArcCompressedSize))("BgaGetArcCompress | 118 return api!(typeof(&BgaGetArcCompressedSize), -1)("BgaGetArcComp
114 } 119 }
115 120
116 WORD BgaGetArcRatio( HARC a ) 121 WORD BgaGetArcRatio( HARC a )
117 { 122 {
118 return api!(typeof(&BgaGetArcRatio))("BgaGetArcRatio")(a); | 123 return api!(typeof(&BgaGetArcRatio), -1)("BgaGetArcRatio")(a);
119 } 124 }
120 125
121 BOOL BgaSetOwnerWindow( HWND a ) 126 BOOL BgaSetOwnerWindow( HWND a )
122 { 127 {
123 BOOL r = api!(typeof(&BgaSetOwnerWindow))("BgaSetOwnerWindow")(a | 128 BOOL r = api!(typeof(&BgaSetOwnerWindow), FALSE)("BgaSetOwnerWin
124 if( r ) BgaSetOwnerWindow_impl(a); 129 if( r ) BgaSetOwnerWindow_impl(a);
125 return r; 130 return r;
126 } 131 }
127 132
128 BOOL BgaClearOwnerWindow() 133 BOOL BgaClearOwnerWindow()
129 { 134 {
130 BOOL r = api!(typeof(&BgaClearOwnerWindow))("BgaClearOwnerWindow | 135 BOOL r = api!(typeof(&BgaClearOwnerWindow), FALSE)("BgaClearOwne
131 BgaClearOwnerWindow_impl(); 136 BgaClearOwnerWindow_impl();
132 return r; 137 return r;
133 } 138 }
134 139
135 alias BOOL function(HWND,UINT,UINT,EXTRACTINGINFOEX*) ARCHIVERPROC; 140 alias BOOL function(HWND,UINT,UINT,EXTRACTINGINFOEX*) ARCHIVERPROC;
136 BOOL BgaSetOwnerWindowEx( HWND a, ARCHIVERPROC* b ) 141 BOOL BgaSetOwnerWindowEx( HWND a, ARCHIVERPROC* b )
137 { 142 {
138 BOOL r = api!(typeof(&BgaSetOwnerWindowEx))("BgaSetOwnerWindowEx | 143 BOOL r = api!(typeof(&BgaSetOwnerWindowEx), FALSE)("BgaSetOwnerW
139 if( r ) BgaSetOwnerWindowEx_impl(a,b); 144 if( r ) BgaSetOwnerWindowEx_impl(a,b);
140 return r; 145 return r;
141 } 146 }
142 147
143 BOOL BgaKillOwnerWindowEx( HWND a ) 148 BOOL BgaKillOwnerWindowEx( HWND a )
144 { 149 {
145 BOOL r = api!(typeof(&BgaKillOwnerWindowEx))("BgaKillOwnerWindow | 150 BOOL r = api!(typeof(&BgaKillOwnerWindowEx), FALSE)("BgaKillOwne
146 BgaClearOwnerWindow_impl(); 151 BgaClearOwnerWindow_impl();
147 return r; 152 return r;
148 } 153 }
149 154
150 alias void* UNLHA_WND_ENUMMEMBPROC; 155 alias void* UNLHA_WND_ENUMMEMBPROC;
151 BOOL BgaSetEnumMembersProc( UNLHA_WND_ENUMMEMBPROC a ) 156 BOOL BgaSetEnumMembersProc( UNLHA_WND_ENUMMEMBPROC a )
152 { 157 {
153 return api!(typeof(&BgaSetEnumMembersProc))("BgaSetEnumMembersPr | 158 return api!(typeof(&BgaSetEnumMembersProc), FALSE)("BgaSetEnumMe
154 } 159 }
155 160
156 BOOL BgaClearEnumMembersProc() 161 BOOL BgaClearEnumMembersProc()
157 { 162 {
158 return api!(typeof(&BgaClearEnumMembersProc))("BgaClearEnumMembe | 163 return api!(typeof(&BgaClearEnumMembersProc), FALSE)("BgaClearEn
159 } 164 }
160 } 165 }
161 166
162 //---------------------------------------------------------------- 167 //----------------------------------------------------------------
163 // 統合アーカイバAPI:実装( Bga ) 168 // 統合アーカイバAPI:実装( Bga )
164 //---------------------------------------------------------------- 169 //----------------------------------------------------------------
165 170