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 1 import win32.windows;
2 2 import std.string;
3 3 import std.file;
4 +import std.traits;
4 5 import util;
5 6 import windll;
6 7 import bga_melter;
7 8 import qbga_gui;
8 9
9 10 //----------------------------------------------------------------
10 11 // API転送処理
11 12 //----------------------------------------------------------------
12 13
13 14 WinDLL g_orig_dll = null;
14 15 UINT WM_ARCEXTRACT;
16 +const ERROR_NO_BGA32DLL = 0x9000;
15 17
16 18 static this()
17 19 {
18 20 g_orig_dll = WinDLL.load( "_Bga32.DLL" );
19 21 WM_ARCEXTRACT = RegisterWindowMessage("wm_arcextract");
20 22 }
21 23
22 24 static ~this()
23 25 {
24 - g_orig_dll.close();
26 + if(g_orig_dll)
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 )
30 - {
31 - return g_orig_dll.get_api!(FnT)( name );
32 - }
32 + FnT def = function(ParameterTypeTuple!(FnT) xs) {
33 + return cast(ReturnType!(FnT))defaultR;
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 41 // 統合アーカイバAPI:転送
37 42 //----------------------------------------------------------------
38 43
39 44 extern(Windows)
40 45 {
41 46 int Bga( HWND a, immutable char* b, char* c, DWORD d )
42 47 {
43 48 int r = Bga_impl( a, b.fromStringz() );
44 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,c,d);
46 51 return r;
47 52 }
48 53
49 54 WORD QBgaGetVersion()
50 55 {
51 - return 5;
56 + return 6;
52 57 }
53 58
54 59 WORD BgaGetVersion()
55 60 {
56 - return api!(typeof(&BgaGetVersion))("BgaGetVersion")();
61 + return api!(typeof(&BgaGetVersion), 0)("BgaGetVersion")();
57 62 }
58 63
59 64 BOOL BgaGetRunning()
60 65 {
61 - return api!(typeof(&BgaGetRunning))("BgaGetRunning")();
66 + return api!(typeof(&BgaGetRunning), FALSE)("BgaGetRunning")();
62 67 }
63 68
64 69 BOOL BgaCheckArchive( char* a, int b )
65 70 {
66 - return api!(typeof(&BgaCheckArchive))("BgaCheckArchive")(a,b);
71 + return api!(typeof(&BgaCheckArchive), FALSE)("BgaCheckArchive")(a,b);
67 72 }
68 73
69 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)("BgaConfigDialog")(a,b,c);
72 77 }
73 78
74 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 84 BOOL BgaQueryFunctionList( int a )
80 85 {
81 - return api!(typeof(&BgaQueryFunctionList))("BgaQueryFunctionList")(a);
86 + return api!(typeof(&BgaQueryFunctionList), FALSE)("BgaQueryFunctionList")(a);
82 87 }
83 88
84 89 alias void* HARC;
85 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 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 100 alias void* LPINDIVIDUALINFO;
96 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 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 111 DWORD BgaGetArcOriginalSize( HARC a )
107 112 {
108 - return api!(typeof(&BgaGetArcOriginalSize))("BgaGetArcOriginalSize")(a);
113 + return api!(typeof(&BgaGetArcOriginalSize), -1)("BgaGetArcOriginalSize")(a);
109 114 }
110 115
111 116 DWORD BgaGetArcCompressedSize( HARC a )
112 117 {
113 - return api!(typeof(&BgaGetArcCompressedSize))("BgaGetArcCompressedSize")(a);
118 + return api!(typeof(&BgaGetArcCompressedSize), -1)("BgaGetArcCompressedSize")(a);
114 119 }
115 120
116 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 126 BOOL BgaSetOwnerWindow( HWND a )
122 127 {
123 - BOOL r = api!(typeof(&BgaSetOwnerWindow))("BgaSetOwnerWindow")(a);
128 + BOOL r = api!(typeof(&BgaSetOwnerWindow), FALSE)("BgaSetOwnerWindow")(a);
124 129 if( r ) BgaSetOwnerWindow_impl(a);
125 130 return r;
126 131 }
127 132
128 133 BOOL BgaClearOwnerWindow()
129 134 {
130 - BOOL r = api!(typeof(&BgaClearOwnerWindow))("BgaClearOwnerWindow")();
135 + BOOL r = api!(typeof(&BgaClearOwnerWindow), FALSE)("BgaClearOwnerWindow")();
131 136 BgaClearOwnerWindow_impl();
132 137 return r;
133 138 }
134 139
135 140 alias BOOL function(HWND,UINT,UINT,EXTRACTINGINFOEX*) ARCHIVERPROC;
136 141 BOOL BgaSetOwnerWindowEx( HWND a, ARCHIVERPROC* b )
137 142 {
138 - BOOL r = api!(typeof(&BgaSetOwnerWindowEx))("BgaSetOwnerWindowEx")(a,b);
143 + BOOL r = api!(typeof(&BgaSetOwnerWindowEx), FALSE)("BgaSetOwnerWindowEx")(a,b);
139 144 if( r ) BgaSetOwnerWindowEx_impl(a,b);
140 145 return r;
141 146 }
142 147
143 148 BOOL BgaKillOwnerWindowEx( HWND a )
144 149 {
145 - BOOL r = api!(typeof(&BgaKillOwnerWindowEx))("BgaKillOwnerWindowEx")(a);
150 + BOOL r = api!(typeof(&BgaKillOwnerWindowEx), FALSE)("BgaKillOwnerWindowEx")(a);
146 151 BgaClearOwnerWindow_impl();
147 152 return r;
148 153 }
149 154
150 155 alias void* UNLHA_WND_ENUMMEMBPROC;
151 156 BOOL BgaSetEnumMembersProc( UNLHA_WND_ENUMMEMBPROC a )
152 157 {
153 - return api!(typeof(&BgaSetEnumMembersProc))("BgaSetEnumMembersProc")(a);
158 + return api!(typeof(&BgaSetEnumMembersProc), FALSE)("BgaSetEnumMembersProc")(a);
154 159 }
155 160
156 161 BOOL BgaClearEnumMembersProc()
157 162 {
158 - return api!(typeof(&BgaClearEnumMembersProc))("BgaClearEnumMembersProc")();
163 + return api!(typeof(&BgaClearEnumMembersProc), FALSE)("BgaClearEnumMembersProc")();
159 164 }
160 165 }
161 166
162 167 //----------------------------------------------------------------
163 168 // 統合アーカイバAPI:実装( Bga )
164 169 //----------------------------------------------------------------
165 170