OSDN Git Service

Fix bugs of simultaneous connection.
[ffftp/ffftp.git] / mbswrapper.c
1 // mbswrapper.c\r
2 // Copyright (C) 2011 Suguru Kawamoto\r
3 // マルチバイト文字ワイド文字APIラッパー\r
4 // マルチバイト文字はUTF-8、ワイド文字はUTF-16であるものとする\r
5 // 全ての制御用の文字はASCIIの範囲であるため、Shift_JISとUTF-8間の変換は不要\r
6 \r
7 #define UNICODE\r
8 #define _UNICODE\r
9 \r
10 #include <stdio.h>\r
11 #include <tchar.h>\r
12 #include <direct.h>\r
13 #include <windows.h>\r
14 #include <commctrl.h>\r
15 #include <shlobj.h>\r
16 #include <htmlhelp.h>\r
17 \r
18 #define DO_NOT_REPLACE\r
19 #include "mbswrapper.h"\r
20 \r
21 // マルチバイト文字列からワイド文字列へ変換\r
22 int MtoW(LPWSTR pDst, int size, LPCSTR pSrc, int count)\r
23 {\r
24         if(pSrc < (LPCSTR)0x00010000 || pSrc == (LPCSTR)~0)\r
25                 return 0;\r
26         if(pDst)\r
27                 return MultiByteToWideChar(CP_UTF8, 0, pSrc, count, pDst, size);\r
28         return MultiByteToWideChar(CP_UTF8, 0, pSrc, count, NULL, 0);\r
29 }\r
30 \r
31 // ワイド文字列からマルチバイト文字列へ変換\r
32 int WtoM(LPSTR pDst, int size, LPCWSTR pSrc, int count)\r
33 {\r
34         if(pSrc < (LPCWSTR)0x00010000 || pSrc == (LPCWSTR)~0)\r
35                 return 0;\r
36         if(pDst)\r
37                 return WideCharToMultiByte(CP_UTF8, 0, pSrc, count, pDst, size, NULL, NULL);\r
38         return WideCharToMultiByte(CP_UTF8, 0, pSrc, count, NULL, 0, NULL, NULL);\r
39 }\r
40 \r
41 // Shift_JIS文字列からワイド文字列へ変換\r
42 int AtoW(LPWSTR pDst, int size, LPCSTR pSrc, int count)\r
43 {\r
44         if(pSrc < (LPCSTR)0x00010000 || pSrc == (LPCSTR)~0)\r
45                 return 0;\r
46         if(pDst)\r
47                 return MultiByteToWideChar(CP_ACP, 0, pSrc, count, pDst, size);\r
48         return MultiByteToWideChar(CP_ACP, 0, pSrc, count, NULL, 0);\r
49 }\r
50 \r
51 // ワイド文字列からShift_JIS文字列へ変換\r
52 int WtoA(LPSTR pDst, int size, LPCWSTR pSrc, int count)\r
53 {\r
54         if(pSrc < (LPCWSTR)0x00010000 || pSrc == (LPCWSTR)~0)\r
55                 return 0;\r
56         if(pDst)\r
57                 return WideCharToMultiByte(CP_ACP, 0, pSrc, count, pDst, size, NULL, NULL);\r
58         return WideCharToMultiByte(CP_ACP, 0, pSrc, count, NULL, 0, NULL, NULL);\r
59 }\r
60 \r
61 // マルチバイト文字列バッファ終端を強制的にNULLで置換\r
62 int TerminateStringM(LPSTR lpString, int size)\r
63 {\r
64         int i;\r
65         if(lpString < (LPSTR)0x00010000 || lpString == (LPSTR)~0)\r
66                 return 0;\r
67         for(i = 0; i < size; i++)\r
68         {\r
69                 if(lpString[i] == '\0')\r
70                         return i;\r
71         }\r
72         i--;\r
73         lpString[i] = '\0';\r
74         return i;\r
75 }\r
76 \r
77 // ワイド文字列バッファ終端を強制的にNULLで置換\r
78 int TerminateStringW(LPWSTR lpString, int size)\r
79 {\r
80         int i;\r
81         if(lpString < (LPWSTR)0x00010000 || lpString == (LPWSTR)~0)\r
82                 return 0;\r
83         for(i = 0; i < size; i++)\r
84         {\r
85                 if(lpString[i] == L'\0')\r
86                         return i;\r
87         }\r
88         i--;\r
89         lpString[i] = L'\0';\r
90         return i;\r
91 }\r
92 \r
93 // Shift_JIS文字列バッファ終端を強制的にNULLで置換\r
94 int TerminateStringA(LPSTR lpString, int size)\r
95 {\r
96         int i;\r
97         if(lpString < (LPSTR)0x00010000 || lpString == (LPSTR)~0)\r
98                 return 0;\r
99         for(i = 0; i < size; i++)\r
100         {\r
101                 if(lpString[i] == '\0')\r
102                         return i;\r
103         }\r
104         i--;\r
105         lpString[i] = '\0';\r
106         return i;\r
107 }\r
108 \r
109 // NULL区切り複数マルチバイト文字列の長さを取得\r
110 size_t GetMultiStringLengthM(LPCSTR lpString)\r
111 {\r
112         size_t i;\r
113         if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)\r
114                 return 0;\r
115         i = 0;\r
116         while(lpString[i] != '\0' || lpString[i + 1] != '\0')\r
117         {\r
118                 i++;\r
119         }\r
120         i++;\r
121         return i;\r
122 }\r
123 \r
124 // NULL区切り複数ワイド文字列の長さを取得\r
125 size_t GetMultiStringLengthW(LPCWSTR lpString)\r
126 {\r
127         size_t i;\r
128         if(lpString < (LPCWSTR)0x00010000 || lpString == (LPCWSTR)~0)\r
129                 return 0;\r
130         i = 0;\r
131         while(lpString[i] != L'\0' || lpString[i + 1] != L'\0')\r
132         {\r
133                 i++;\r
134         }\r
135         i++;\r
136         return i;\r
137 }\r
138 \r
139 // NULL区切り複数Shift_JIS文字列の長さを取得\r
140 size_t GetMultiStringLengthA(LPCSTR lpString)\r
141 {\r
142         size_t i;\r
143         if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)\r
144                 return 0;\r
145         i = 0;\r
146         while(lpString[i] != '\0' || lpString[i + 1] != '\0')\r
147         {\r
148                 i++;\r
149         }\r
150         i++;\r
151         return i;\r
152 }\r
153 \r
154 // NULL区切りマルチバイト文字列からワイド文字列へ変換\r
155 int MtoWMultiString(LPWSTR pDst, int size, LPCSTR pSrc)\r
156 {\r
157         int i;\r
158         if(pSrc < (LPCSTR)0x00010000 || pSrc == (LPCSTR)~0)\r
159                 return 0;\r
160         if(!pDst)\r
161                 return GetMultiStringLengthM(pSrc);\r
162         i = 0;\r
163         while(*pSrc != '\0')\r
164         {\r
165                 i += MultiByteToWideChar(CP_UTF8, 0, pSrc, -1, pDst + i, size - i - 1);\r
166                 pSrc += strlen(pSrc) + 1;\r
167         }\r
168         pDst[i] = L'\0';\r
169         return i;\r
170 }\r
171 \r
172 // NULL区切りワイド文字列からマルチバイト文字列へ変換\r
173 int WtoMMultiString(LPSTR pDst, int size, LPCWSTR pSrc)\r
174 {\r
175         int i;\r
176         if(pSrc < (LPCWSTR)0x00010000 || pSrc == (LPCWSTR)~0)\r
177                 return 0;\r
178         if(!pDst)\r
179                 return GetMultiStringLengthW(pSrc);\r
180         i = 0;\r
181         while(*pSrc != L'\0')\r
182         {\r
183                 i += WideCharToMultiByte(CP_UTF8, 0, pSrc, -1, pDst + i, size - i - 1, NULL, NULL);\r
184                 pSrc += wcslen(pSrc) + 1;\r
185         }\r
186         pDst[i] = '\0';\r
187         return i;\r
188 }\r
189 \r
190 // NULL区切りShift_JIS文字列からワイド文字列へ変換\r
191 int AtoWMultiString(LPWSTR pDst, int size, LPCSTR pSrc)\r
192 {\r
193         int i;\r
194         if(pSrc < (LPCSTR)0x00010000 || pSrc == (LPCSTR)~0)\r
195                 return 0;\r
196         if(!pDst)\r
197                 return GetMultiStringLengthA(pSrc);\r
198         i = 0;\r
199         while(*pSrc != '\0')\r
200         {\r
201                 i += MultiByteToWideChar(CP_ACP, 0, pSrc, -1, pDst + i, size - i - 1);\r
202                 pSrc += strlen(pSrc) + 1;\r
203         }\r
204         pDst[i] = L'\0';\r
205         return i;\r
206 }\r
207 \r
208 // NULL区切りワイド文字列からShift_JIS文字列へ変換\r
209 int WtoAMultiString(LPSTR pDst, int size, LPCWSTR pSrc)\r
210 {\r
211         int i;\r
212         if(pSrc < (LPCWSTR)0x00010000 || pSrc == (LPCWSTR)~0)\r
213                 return 0;\r
214         if(!pDst)\r
215                 return GetMultiStringLengthW(pSrc);\r
216         i = 0;\r
217         while(*pSrc != L'\0')\r
218         {\r
219                 i += WideCharToMultiByte(CP_ACP, 0, pSrc, -1, pDst + i, size - i - 1, NULL, NULL);\r
220                 pSrc += wcslen(pSrc) + 1;\r
221         }\r
222         pDst[i] = '\0';\r
223         return i;\r
224 }\r
225 \r
226 // マルチバイト文字列用のメモリを確保\r
227 char* AllocateStringM(int size)\r
228 {\r
229         char* p;\r
230         // 0が指定される場合があるため1文字分追加\r
231         p = (char*)malloc(sizeof(char) * (size + 1));\r
232         // 念のため先頭にNULL文字を代入\r
233         if(p)\r
234                 *p = '\0';\r
235         return p;\r
236 }\r
237 \r
238 // ワイド文字列用のメモリを確保\r
239 wchar_t* AllocateStringW(int size)\r
240 {\r
241         wchar_t* p;\r
242         // 0が指定される場合があるため1文字分追加\r
243         p = (wchar_t*)malloc(sizeof(wchar_t) * (size + 1));\r
244         // 念のため先頭にNULL文字を代入\r
245         if(p)\r
246                 *p = L'\0';\r
247         return p;\r
248 }\r
249 \r
250 // Shift_JIS文字列用のメモリを確保\r
251 char* AllocateStringA(int size)\r
252 {\r
253         char* p;\r
254         // 0が指定される場合があるため1文字分追加\r
255         p = (char*)malloc(sizeof(char) * (size + 1));\r
256         // 念のため先頭にNULL文字を代入\r
257         if(p)\r
258                 *p = '\0';\r
259         return p;\r
260 }\r
261 \r
262 // メモリを確保してマルチバイト文字列からワイド文字列へ変換\r
263 // リソースIDならば元の値を返す\r
264 wchar_t* DuplicateMtoW(LPCSTR lpString, int c)\r
265 {\r
266         wchar_t* p;\r
267         int i;\r
268         if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)\r
269                 return (wchar_t*)lpString;\r
270         if(c < 0)\r
271                 c = strlen(lpString);\r
272         p = AllocateStringW(MtoW(NULL, 0, lpString, c) + 1);\r
273         if(p)\r
274         {\r
275                 i = MtoW(p, 65535, lpString, c);\r
276                 p[i] = L'\0';\r
277         }\r
278         return p;\r
279 }\r
280 \r
281 // 指定したサイズのメモリを確保してマルチバイト文字列からワイド文字列へ変換\r
282 // リソースIDならば元の値を返す\r
283 wchar_t* DuplicateMtoWBuffer(LPCSTR lpString, int c, int size)\r
284 {\r
285         wchar_t* p;\r
286         int i;\r
287         if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)\r
288                 return (wchar_t*)lpString;\r
289         if(c < 0)\r
290                 c = strlen(lpString);\r
291         p = AllocateStringW(size);\r
292         if(p)\r
293         {\r
294                 i = MtoW(p, size, lpString, c);\r
295                 p[i] = L'\0';\r
296         }\r
297         return p;\r
298 }\r
299 \r
300 // メモリを確保してNULL区切りマルチバイト文字列からワイド文字列へ変換\r
301 // リソースIDならば元の値を返す\r
302 wchar_t* DuplicateMtoWMultiString(LPCSTR lpString)\r
303 {\r
304         int count;\r
305         wchar_t* p;\r
306         if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)\r
307                 return (wchar_t*)lpString;\r
308         count = GetMultiStringLengthM(lpString) + 1;\r
309         p = AllocateStringW(count);\r
310         if(p)\r
311                 MtoW(p, count, lpString, count);\r
312         return p;\r
313 }\r
314 \r
315 // 指定したサイズのメモリを確保してNULL区切りマルチバイト文字列からワイド文字列へ変換\r
316 // リソースIDならば元の値を返す\r
317 wchar_t* DuplicateMtoWMultiStringBuffer(LPCSTR lpString, int size)\r
318 {\r
319         int count;\r
320         wchar_t* p;\r
321         if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)\r
322                 return (wchar_t*)lpString;\r
323         count = GetMultiStringLengthM(lpString) + 1;\r
324         p = AllocateStringW(size);\r
325         if(p)\r
326         {\r
327                 MtoW(p, size, lpString, count);\r
328                 p[size - 2] = L'\0';\r
329                 p[size - 1] = L'\0';\r
330         }\r
331         return p;\r
332 }\r
333 \r
334 // メモリを確保してワイド文字列からマルチバイト文字列へ変換\r
335 // リソースIDならば元の値を返す\r
336 char* DuplicateWtoM(LPCWSTR lpString, int c)\r
337 {\r
338         char* p;\r
339         int i;\r
340         if(lpString < (LPCWSTR)0x00010000 || lpString == (LPCWSTR)~0)\r
341                 return (char*)lpString;\r
342         if(c < 0)\r
343                 c = wcslen(lpString);\r
344         p = AllocateStringM(WtoM(NULL, 0, lpString, c) + 1);\r
345         if(p)\r
346         {\r
347                 i = WtoM(p, 65535, lpString, c);\r
348                 p[i] = L'\0';\r
349         }\r
350         return p;\r
351 }\r
352 \r
353 // メモリを確保してShift_JIS文字列からワイド文字列へ変換\r
354 // リソースIDならば元の値を返す\r
355 wchar_t* DuplicateAtoW(LPCSTR lpString, int c)\r
356 {\r
357         wchar_t* p;\r
358         int i;\r
359         if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)\r
360                 return (wchar_t*)lpString;\r
361         if(c < 0)\r
362                 c = strlen(lpString);\r
363         p = AllocateStringW(AtoW(NULL, 0, lpString, c) + 1);\r
364         if(p)\r
365         {\r
366                 i = AtoW(p, 65535, lpString, c);\r
367                 p[i] = L'\0';\r
368         }\r
369         return p;\r
370 }\r
371 \r
372 // メモリを確保してワイド文字列からShift_JIS文字列へ変換\r
373 // リソースIDならば元の値を返す\r
374 char* DuplicateWtoA(LPCWSTR lpString, int c)\r
375 {\r
376         char* p;\r
377         int i;\r
378         if(lpString < (LPCWSTR)0x00010000 || lpString == (LPCWSTR)~0)\r
379                 return (char*)lpString;\r
380         if(c < 0)\r
381                 c = wcslen(lpString);\r
382         p = AllocateStringA(WtoA(NULL, 0, lpString, c) + 1);\r
383         if(p)\r
384         {\r
385                 i = WtoA(p, 65535, lpString, c);\r
386                 p[i] = L'\0';\r
387         }\r
388         return p;\r
389 }\r
390 \r
391 // マルチバイト文字列からコードポイントと次のポインタを取得\r
392 // エンコードが不正な場合は0x80000000を返す\r
393 DWORD GetNextCharM(LPCSTR lpString, LPCSTR* ppNext)\r
394 {\r
395         DWORD Code;\r
396         int i;\r
397         Code = 0;\r
398         if((*lpString & 0xfe) == 0xfc)\r
399         {\r
400                 i = 5;\r
401                 Code |= (DWORD)*lpString & 0x01;\r
402         }\r
403         else if((*lpString & 0xfc) == 0xf8)\r
404         {\r
405                 i = 4;\r
406                 Code |= (DWORD)*lpString & 0x03;\r
407         }\r
408         else if((*lpString & 0xf8) == 0xf0)\r
409         {\r
410                 i = 3;\r
411                 Code |= (DWORD)*lpString & 0x07;\r
412         }\r
413         else if((*lpString & 0xf0) == 0xe0)\r
414         {\r
415                 i = 2;\r
416                 Code |= (DWORD)*lpString & 0x0f;\r
417         }\r
418         else if((*lpString & 0xe0) == 0xc0)\r
419         {\r
420                 i = 1;\r
421                 Code |= (DWORD)*lpString & 0x1f;\r
422         }\r
423         else if((*lpString & 0x80) == 0x00)\r
424         {\r
425                 i = 0;\r
426                 Code |= (DWORD)*lpString & 0x7f;\r
427         }\r
428         else\r
429                 i = -1;\r
430         lpString++;\r
431         while((*lpString & 0xc0) == 0x80)\r
432         {\r
433                 i--;\r
434                 Code = Code << 6;\r
435                 Code |= (DWORD)*lpString & 0x3f;\r
436                 lpString++;\r
437         }\r
438         if(i != 0)\r
439                 Code = 0x80000000;\r
440         if(ppNext)\r
441                 *ppNext = lpString;\r
442         return Code;\r
443 }\r
444 \r
445 // マルチバイト文字列の冗長表現を修正\r
446 // 修正があればTRUEを返す\r
447 // 修正後の文字列の長さは元の文字列の長さ以下のためpDstとpSrcに同じ値を指定可能\r
448 BOOL FixStringM(LPSTR pDst, LPCSTR pSrc)\r
449 {\r
450         BOOL bResult;\r
451         char* p;\r
452         DWORD Code;\r
453         int i;\r
454         char c;\r
455         bResult = FALSE;\r
456         p = (char*)pSrc;\r
457         while(*pSrc != '\0')\r
458         {\r
459                 Code = GetNextCharM(pSrc, &pSrc);\r
460                 if(Code & 0x80000000)\r
461                         continue;\r
462                 else if(Code & 0x7c000000)\r
463                 {\r
464                         i = 5;\r
465                         c = (char)(0xfc | (Code >> (6 * i)));\r
466                 }\r
467                 else if(Code & 0x03e00000)\r
468                 {\r
469                         i = 4;\r
470                         c = (char)(0xf8 | (Code >> (6 * i)));\r
471                 }\r
472                 else if(Code & 0x001f0000)\r
473                 {\r
474                         i = 3;\r
475                         c = (char)(0xf0 | (Code >> (6 * i)));\r
476                 }\r
477                 else if(Code & 0x0000f800)\r
478                 {\r
479                         i = 2;\r
480                         c = (char)(0xe0 | (Code >> (6 * i)));\r
481                 }\r
482                 else if(Code & 0x00000780)\r
483                 {\r
484                         i = 1;\r
485                         c = (char)(0xc0 | (Code >> (6 * i)));\r
486                 }\r
487                 else\r
488                 {\r
489                         i = 0;\r
490                         c = (char)Code;\r
491                 }\r
492                 if(c != *p)\r
493                         bResult = TRUE;\r
494                 p++;\r
495                 *pDst = c;\r
496                 pDst++;\r
497                 while(i > 0)\r
498                 {\r
499                         i--;\r
500                         c = (char)(0x80 | ((Code >> (6 * i)) & 0x3f));\r
501                         if(c != *p)\r
502                                 bResult = TRUE;\r
503                         p++;\r
504                         *pDst = c;\r
505                         pDst++;\r
506                 }\r
507         }\r
508         if(*p != '\0')\r
509                 bResult = TRUE;\r
510         *pDst = '\0';\r
511         return bResult;\r
512 }\r
513 \r
514 // NULL区切りマルチバイト文字列の冗長表現を修正\r
515 // 修正があればTRUEを返す\r
516 // 修正後の文字列の長さは元の文字列の長さ以下のためpDstとpSrcに同じ値を指定可能\r
517 BOOL FixMultiStringM(LPSTR pDst, LPCSTR pSrc)\r
518 {\r
519         BOOL bResult;\r
520         int Length;\r
521         bResult = FALSE;\r
522         while(*pSrc != '\0')\r
523         {\r
524                 Length = strlen(pSrc) + 1;\r
525                 bResult = bResult | FixStringM(pDst, pSrc);\r
526                 pSrc += Length;\r
527                 pDst += strlen(pDst) + 1;\r
528         }\r
529         *pDst = '\0';\r
530         return bResult;\r
531 }\r
532 \r
533 // マルチバイト文字列の冗長表現を確認\r
534 // 冗長表現があればTRUEを返す\r
535 BOOL CheckStringM(LPCSTR lpString)\r
536 {\r
537         BOOL bResult;\r
538         char* p;\r
539         bResult = FALSE;\r
540         p = AllocateStringM(strlen(lpString) + 1);\r
541         if(p)\r
542         {\r
543                 bResult = FixStringM(p, lpString);\r
544                 FreeDuplicatedString(p);\r
545         }\r
546         return bResult;\r
547 }\r
548 \r
549 // NULL区切りマルチバイト文字列の冗長表現を確認\r
550 // 冗長表現があればTRUEを返す\r
551 BOOL CheckMultiStringM(LPCSTR lpString)\r
552 {\r
553         BOOL bResult;\r
554         char* p;\r
555         bResult = FALSE;\r
556         p = AllocateStringM(GetMultiStringLengthM(lpString) + 1);\r
557         if(p)\r
558         {\r
559                 bResult = FixMultiStringM(p, lpString);\r
560                 FreeDuplicatedString(p);\r
561         }\r
562         return bResult;\r
563 }\r
564 \r
565 // 文字列用に確保したメモリを開放\r
566 // リソースIDならば何もしない\r
567 void FreeDuplicatedString(void* p)\r
568 {\r
569         if(p < (void*)0x00010000 || p == (void*)~0)\r
570                 return;\r
571         free(p);\r
572 }\r
573 \r
574 // 以下ラッパー\r
575 // 戻り値バッファ r\r
576 // ワイド文字バッファ pw%d\r
577 // マルチバイト文字バッファ pm%d\r
578 // 引数バッファ a%d\r
579 \r
580 #pragma warning(disable:4102)\r
581 #define START_ROUTINE                                   do{\r
582 #define END_ROUTINE                                             }while(0);end_of_routine:\r
583 #define QUIT_ROUTINE                                    goto end_of_routine;\r
584 \r
585 int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)\r
586 {\r
587         int r = 0;\r
588         char* pm0 = NULL;\r
589 START_ROUTINE\r
590         pm0 = DuplicateWtoM(lpCmdLine, -1);\r
591         r = WinMainM(hInstance, hPrevInstance, pm0, nCmdShow);\r
592 END_ROUTINE\r
593         FreeDuplicatedString(pm0);\r
594         return r;\r
595 }\r
596 \r
597 HMODULE LoadLibraryM(LPCSTR lpLibFileName)\r
598 {\r
599         HMODULE r = NULL;\r
600         wchar_t* pw0 = NULL;\r
601 START_ROUTINE\r
602         pw0 = DuplicateMtoW(lpLibFileName, -1);\r
603         r = LoadLibraryW(pw0);\r
604 END_ROUTINE\r
605         FreeDuplicatedString(pw0);\r
606         return r;\r
607 }\r
608 \r
609 HANDLE CreateFileM(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)\r
610 {\r
611         HANDLE r = INVALID_HANDLE_VALUE;\r
612         wchar_t* pw0 = NULL;\r
613 START_ROUTINE\r
614         pw0 = DuplicateMtoW(lpFileName, -1);\r
615         r = CreateFileW(pw0, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);\r
616 END_ROUTINE\r
617         FreeDuplicatedString(pw0);\r
618         return r;\r
619 }\r
620 \r
621 int MessageBoxM(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)\r
622 {\r
623         int r = IDOK;\r
624         wchar_t* pw0 = NULL;\r
625         wchar_t* pw1 = NULL;\r
626 START_ROUTINE\r
627         pw0 = DuplicateMtoW(lpText, -1);\r
628         pw1 = DuplicateMtoW(lpCaption, -1);\r
629         r = MessageBoxW(hWnd, pw0, pw1, uType);\r
630 END_ROUTINE\r
631         FreeDuplicatedString(pw0);\r
632         FreeDuplicatedString(pw1);\r
633         return r;\r
634 }\r
635 \r
636 HANDLE FindFirstFileM(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)\r
637 {\r
638         HANDLE r = INVALID_HANDLE_VALUE;\r
639         wchar_t* pw0 = NULL;\r
640         WIN32_FIND_DATAW a0;\r
641 START_ROUTINE\r
642         pw0 = DuplicateMtoW(lpFileName, -1);\r
643         r = FindFirstFileW(pw0, &a0);\r
644         if(r != INVALID_HANDLE_VALUE)\r
645         {\r
646                 lpFindFileData->dwFileAttributes = a0.dwFileAttributes;\r
647                 lpFindFileData->ftCreationTime = a0.ftCreationTime;\r
648                 lpFindFileData->ftLastAccessTime = a0.ftLastAccessTime;\r
649                 lpFindFileData->ftLastWriteTime = a0.ftLastWriteTime;\r
650                 lpFindFileData->nFileSizeHigh = a0.nFileSizeHigh;\r
651                 lpFindFileData->nFileSizeLow = a0.nFileSizeLow;\r
652                 lpFindFileData->dwReserved0 = a0.dwReserved0;\r
653                 lpFindFileData->dwReserved1 = a0.dwReserved1;\r
654                 WtoM(lpFindFileData->cFileName, sizeof(lpFindFileData->cFileName), a0.cFileName, -1);\r
655                 WtoM(lpFindFileData->cAlternateFileName, sizeof(lpFindFileData->cAlternateFileName), a0.cAlternateFileName, -1);\r
656         }\r
657 END_ROUTINE\r
658         FreeDuplicatedString(pw0);\r
659         return r;\r
660 }\r
661 \r
662 BOOL FindNextFileM(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData)\r
663 {\r
664         BOOL r = FALSE;\r
665         WIN32_FIND_DATAW a0;\r
666 START_ROUTINE\r
667         r = FindNextFileW(hFindFile, &a0);\r
668         if(r)\r
669         {\r
670                 lpFindFileData->dwFileAttributes = a0.dwFileAttributes;\r
671                 lpFindFileData->ftCreationTime = a0.ftCreationTime;\r
672                 lpFindFileData->ftLastAccessTime = a0.ftLastAccessTime;\r
673                 lpFindFileData->ftLastWriteTime = a0.ftLastWriteTime;\r
674                 lpFindFileData->nFileSizeHigh = a0.nFileSizeHigh;\r
675                 lpFindFileData->nFileSizeLow = a0.nFileSizeLow;\r
676                 lpFindFileData->dwReserved0 = a0.dwReserved0;\r
677                 lpFindFileData->dwReserved1 = a0.dwReserved1;\r
678                 WtoM(lpFindFileData->cFileName, sizeof(lpFindFileData->cFileName), a0.cFileName, -1);\r
679                 WtoM(lpFindFileData->cAlternateFileName, sizeof(lpFindFileData->cAlternateFileName), a0.cAlternateFileName, -1);\r
680         }\r
681 END_ROUTINE\r
682         return r;\r
683 }\r
684 \r
685 DWORD GetLogicalDriveStringsM(DWORD nBufferLength, LPSTR lpBuffer)\r
686 {\r
687         DWORD r = 0;\r
688         wchar_t* pw0 = NULL;\r
689 START_ROUTINE\r
690         pw0 = AllocateStringW(nBufferLength * 4);\r
691         GetLogicalDriveStringsW(nBufferLength * 4, pw0);\r
692         WtoMMultiString(lpBuffer, nBufferLength, pw0);\r
693         r = TerminateStringM(lpBuffer, nBufferLength);\r
694 END_ROUTINE\r
695         FreeDuplicatedString(pw0);\r
696         return r;\r
697 }\r
698 \r
699 ATOM RegisterClassExM(CONST WNDCLASSEXA * v0)\r
700 {\r
701         ATOM r = 0;\r
702 START_ROUTINE\r
703         // WNDPROCがShift_JIS用であるため\r
704         r = RegisterClassExA(v0);\r
705 END_ROUTINE\r
706         return r;\r
707 }\r
708 \r
709 HWND CreateWindowExM(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)\r
710 {\r
711         HWND r = NULL;\r
712         wchar_t* pw0 = NULL;\r
713         wchar_t* pw1 = NULL;\r
714 START_ROUTINE\r
715         pw0 = DuplicateMtoW(lpClassName, -1);\r
716         pw1 = DuplicateMtoW(lpWindowName, -1);\r
717         r = CreateWindowExW(dwExStyle, pw0, pw1, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);\r
718 END_ROUTINE\r
719         FreeDuplicatedString(pw0);\r
720         FreeDuplicatedString(pw1);\r
721         return r;\r
722 }\r
723 \r
724 LONG GetWindowLongM(HWND hWnd, int nIndex)\r
725 {\r
726         LONG r = 0;\r
727 START_ROUTINE\r
728         // WNDPROCがShift_JIS用であるため\r
729         if(IsWindowUnicode(hWnd))\r
730                 r = GetWindowLongW(hWnd, nIndex);\r
731         else\r
732                 r = GetWindowLongA(hWnd, nIndex);\r
733 END_ROUTINE\r
734         return r;\r
735 }\r
736 \r
737 LONG SetWindowLongM(HWND hWnd, int nIndex, LONG dwNewLong)\r
738 {\r
739         LONG r = 0;\r
740 START_ROUTINE\r
741         // WNDPROCがShift_JIS用であるため\r
742         if(IsWindowUnicode(hWnd))\r
743                 r = SetWindowLongW(hWnd, nIndex, dwNewLong);\r
744         else\r
745                 r = SetWindowLongA(hWnd, nIndex, dwNewLong);\r
746 END_ROUTINE\r
747         return r;\r
748 }\r
749 \r
750 LONG_PTR GetWindowLongPtrM(HWND hWnd, int nIndex)\r
751 {\r
752         LONG_PTR r = 0;\r
753 START_ROUTINE\r
754         // WNDPROCがShift_JIS用であるため\r
755         if(IsWindowUnicode(hWnd))\r
756                 r = GetWindowLongPtrW(hWnd, nIndex);\r
757         else\r
758                 r = GetWindowLongPtrA(hWnd, nIndex);\r
759 END_ROUTINE\r
760         return r;\r
761 }\r
762 \r
763 LONG_PTR SetWindowLongPtrM(HWND hWnd, int nIndex, LONG_PTR dwNewLong)\r
764 {\r
765         LONG_PTR r = 0;\r
766 START_ROUTINE\r
767         // WNDPROCがShift_JIS用であるため\r
768         if(IsWindowUnicode(hWnd))\r
769                 r = SetWindowLongPtrW(hWnd, nIndex, dwNewLong);\r
770         else\r
771                 r = SetWindowLongPtrA(hWnd, nIndex, dwNewLong);\r
772 END_ROUTINE\r
773         return r;\r
774 }\r
775 \r
776 LRESULT DefWindowProcM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)\r
777 {\r
778         LRESULT r = 0;\r
779 START_ROUTINE\r
780         // WNDPROCがShift_JIS用であるため\r
781         if(IsWindowUnicode(hWnd))\r
782                 r = DefWindowProcW(hWnd, Msg, wParam, lParam);\r
783         else\r
784                 r = DefWindowProcA(hWnd, Msg, wParam, lParam);\r
785 END_ROUTINE\r
786         return r;\r
787 }\r
788 \r
789 LRESULT CallWindowProcM(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)\r
790 {\r
791         LRESULT r = 0;\r
792 START_ROUTINE\r
793         // WNDPROCがShift_JIS用であるため\r
794         if(IsWindowUnicode(hWnd))\r
795                 r = CallWindowProcW(lpPrevWndFunc, hWnd, Msg, wParam, lParam);\r
796         else\r
797                 r = CallWindowProcA(lpPrevWndFunc, hWnd, Msg, wParam, lParam);\r
798 END_ROUTINE\r
799         return r;\r
800 }\r
801 \r
802 LRESULT SendMessageM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)\r
803 {\r
804         LRESULT r = 0;\r
805         wchar_t* pw0 = NULL;\r
806         wchar_t* pw1 = NULL;\r
807         int Size;\r
808         LVITEMA* pmLVItem;\r
809         LVITEMW wLVItem;\r
810         LVFINDINFOA* pmLVFindInfo;\r
811         LVFINDINFOW wLVFindInfo;\r
812         LVCOLUMNA* pmLVColumn;\r
813         LVCOLUMNW wLVColumn;\r
814         TVITEMEXA* pmTVItem;\r
815         TVITEMEXW wTVItem;\r
816         TVINSERTSTRUCTA* pmTVInsert;\r
817         TVINSERTSTRUCTW wTVInsert;\r
818         wchar_t ClassName[MAX_PATH];\r
819 START_ROUTINE\r
820         switch(Msg)\r
821         {\r
822         case WM_SETTEXT:\r
823                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
824                 r = SendMessageW(hWnd, WM_SETTEXT, wParam, (LPARAM)pw0);\r
825                 break;\r
826         case WM_GETTEXT:\r
827                 pw0 = AllocateStringW(wParam * 4);\r
828                 SendMessageW(hWnd, WM_GETTEXT, wParam * 4, (LPARAM)pw0);\r
829                 WtoM((LPSTR)lParam, wParam, pw0, -1);\r
830                 r = TerminateStringM((LPSTR)lParam, wParam);\r
831                 break;\r
832         case WM_GETTEXTLENGTH:\r
833                 Size = SendMessageW(hWnd, WM_GETTEXTLENGTH, wParam, lParam) + 1;\r
834                 pw0 = AllocateStringW(Size);\r
835                 SendMessageW(hWnd, WM_GETTEXT, (WPARAM)Size, (LPARAM)pw0);\r
836                 r = WtoM(NULL, 0, pw0, -1) - 1;\r
837                 break;\r
838         default:\r
839                 GetClassNameW(hWnd, ClassName, sizeof(ClassName) / sizeof(wchar_t));\r
840                 if(_wcsicmp(ClassName, WC_EDITW) == 0)\r
841                 {\r
842                         switch(Msg)\r
843                         {\r
844                         case EM_REPLACESEL:\r
845                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
846                                 r = SendMessageW(hWnd, EM_REPLACESEL, wParam, (LPARAM)pw0);\r
847                                 break;\r
848                         default:\r
849                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
850                                 break;\r
851                         }\r
852                 }\r
853                 else if(_wcsicmp(ClassName, WC_COMBOBOXW) == 0)\r
854                 {\r
855                         switch(Msg)\r
856                         {\r
857                         case CB_ADDSTRING:\r
858                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
859                                 r = SendMessageW(hWnd, CB_ADDSTRING, wParam, (LPARAM)pw0);\r
860                                 break;\r
861                         case CB_GETLBTEXT:\r
862                                 Size = SendMessageW(hWnd, CB_GETLBTEXTLEN, wParam, 0) + 1;\r
863                                 pw0 = AllocateStringW(Size);\r
864                                 SendMessageW(hWnd, CB_GETLBTEXT, wParam, (LPARAM)pw0);\r
865                                 // バッファ長不明のためオーバーランの可能性あり\r
866                                 WtoM((LPSTR)lParam, Size * 4, pw0, -1);\r
867                                 r = TerminateStringM((LPSTR)lParam, Size * 4);\r
868                                 break;\r
869                         case CB_GETLBTEXTLEN:\r
870                                 Size = SendMessageW(hWnd, CB_GETLBTEXTLEN, wParam, 0) + 1;\r
871                                 pw0 = AllocateStringW(Size);\r
872                                 SendMessageW(hWnd, WM_GETTEXT, wParam, (LPARAM)pw0);\r
873                                 r = WtoM(NULL, 0, pw0, -1) - 1;\r
874                                 break;\r
875                         case CB_INSERTSTRING:\r
876                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
877                                 r = SendMessageW(hWnd, CB_INSERTSTRING, wParam, (LPARAM)pw0);\r
878                                 break;\r
879                         case CB_FINDSTRINGEXACT:\r
880                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
881                                 r = SendMessageW(hWnd, CB_FINDSTRINGEXACT, wParam, (LPARAM)pw0);\r
882                                 break;\r
883                         default:\r
884                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
885                                 break;\r
886                         }\r
887                 }\r
888                 else if(_wcsicmp(ClassName, WC_LISTBOXW) == 0)\r
889                 {\r
890                         switch(Msg)\r
891                         {\r
892                         case LB_ADDSTRING:\r
893                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
894                                 r = SendMessageW(hWnd, LB_ADDSTRING, wParam, (LPARAM)pw0);\r
895                                 break;\r
896                         case LB_INSERTSTRING:\r
897                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
898                                 r = SendMessageW(hWnd, LB_INSERTSTRING, wParam, (LPARAM)pw0);\r
899                                 break;\r
900                         case LB_GETTEXT:\r
901                                 Size = SendMessageW(hWnd, LB_GETTEXTLEN, wParam, 0) + 1;\r
902                                 pw0 = AllocateStringW(Size);\r
903                                 SendMessageW(hWnd, LB_GETTEXT, wParam, (LPARAM)pw0);\r
904                                 // バッファ長不明のためオーバーランの可能性あり\r
905                                 WtoM((LPSTR)lParam, Size * 4, pw0, -1);\r
906                                 r = TerminateStringM((LPSTR)lParam, Size * 4);\r
907                                 break;\r
908                         case LB_GETTEXTLEN:\r
909                                 Size = SendMessageW(hWnd, LB_GETTEXTLEN, wParam, 0) + 1;\r
910                                 pw0 = AllocateStringW(Size);\r
911                                 SendMessageW(hWnd, WM_GETTEXT, wParam, (LPARAM)pw0);\r
912                                 r = WtoM(NULL, 0, pw0, -1) - 1;\r
913                                 break;\r
914                         default:\r
915                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
916                                 break;\r
917                         }\r
918                 }\r
919                 else if(_wcsicmp(ClassName, WC_LISTVIEWW) == 0)\r
920                 {\r
921                         switch(Msg)\r
922                         {\r
923                         case LVM_GETITEMA:\r
924                                 pmLVItem = (LVITEMA*)lParam;\r
925                                 wLVItem.mask = pmLVItem->mask;\r
926                                 wLVItem.iItem = pmLVItem->iItem;\r
927                                 wLVItem.iSubItem = pmLVItem->iSubItem;\r
928                                 wLVItem.state = pmLVItem->state;\r
929                                 wLVItem.stateMask = pmLVItem->stateMask;\r
930                                 if(pmLVItem->mask & LVIF_TEXT)\r
931                                 {\r
932                                         Size = pmLVItem->cchTextMax * 4;\r
933                                         pw0 = AllocateStringW(Size);\r
934                                         wLVItem.pszText = pw0;\r
935                                         wLVItem.cchTextMax = Size;\r
936                                 }\r
937                                 wLVItem.iImage = pmLVItem->iImage;\r
938                                 wLVItem.lParam = pmLVItem->lParam;\r
939                                 wLVItem.iIndent = pmLVItem->iIndent;\r
940                                 r = SendMessageW(hWnd, LVM_GETITEMW, wParam, (LPARAM)&wLVItem);\r
941                                 pmLVItem->mask = wLVItem.mask;\r
942                                 pmLVItem->iItem = wLVItem.iItem;\r
943                                 pmLVItem->iSubItem = wLVItem.iSubItem;\r
944                                 pmLVItem->state = wLVItem.state;\r
945                                 pmLVItem->stateMask = wLVItem.stateMask;\r
946                                 if(pmLVItem->mask & LVIF_TEXT)\r
947                                 {\r
948                                         WtoM(pmLVItem->pszText, pmLVItem->cchTextMax, wLVItem.pszText, -1);\r
949                                         TerminateStringM(pmLVItem->pszText, pmLVItem->cchTextMax);\r
950                                 }\r
951                                 pmLVItem->iImage = wLVItem.iImage;\r
952                                 pmLVItem->lParam = wLVItem.lParam;\r
953                                 pmLVItem->iIndent = wLVItem.iIndent;\r
954                                 break;\r
955                         case LVM_SETITEMA:\r
956                                 pmLVItem = (LVITEMA*)lParam;\r
957                                 wLVItem.mask = pmLVItem->mask;\r
958                                 wLVItem.iItem = pmLVItem->iItem;\r
959                                 wLVItem.iSubItem = pmLVItem->iSubItem;\r
960                                 wLVItem.state = pmLVItem->state;\r
961                                 wLVItem.stateMask = pmLVItem->stateMask;\r
962                                 if(pmLVItem->mask & LVIF_TEXT)\r
963                                 {\r
964                                         pw0 = DuplicateMtoW(pmLVItem->pszText, -1);\r
965                                         wLVItem.pszText = pw0;\r
966                                         // TODO: cchTextMaxの確認\r
967                                         wLVItem.cchTextMax = pmLVItem->cchTextMax;\r
968                                 }\r
969                                 wLVItem.iImage = pmLVItem->iImage;\r
970                                 wLVItem.lParam = pmLVItem->lParam;\r
971                                 wLVItem.iIndent = pmLVItem->iIndent;\r
972                                 r = SendMessageW(hWnd, LVM_SETITEMW, wParam, (LPARAM)&wLVItem);\r
973                                 break;\r
974                         case LVM_INSERTITEMA:\r
975                                 pmLVItem = (LVITEMA*)lParam;\r
976                                 wLVItem.mask = pmLVItem->mask;\r
977                                 wLVItem.iItem = pmLVItem->iItem;\r
978                                 wLVItem.iSubItem = pmLVItem->iSubItem;\r
979                                 wLVItem.state = pmLVItem->state;\r
980                                 wLVItem.stateMask = pmLVItem->stateMask;\r
981                                 if(pmLVItem->mask & LVIF_TEXT)\r
982                                 {\r
983                                         pw0 = DuplicateMtoW(pmLVItem->pszText, -1);\r
984                                         wLVItem.pszText = pw0;\r
985                                         // TODO: cchTextMaxの確認\r
986                                         wLVItem.cchTextMax = pmLVItem->cchTextMax;\r
987                                 }\r
988                                 wLVItem.iImage = pmLVItem->iImage;\r
989                                 wLVItem.lParam = pmLVItem->lParam;\r
990                                 wLVItem.iIndent = pmLVItem->iIndent;\r
991                                 r = SendMessageW(hWnd, LVM_INSERTITEMW, wParam, (LPARAM)&wLVItem);\r
992                                 break;\r
993                         case LVM_FINDITEMA:\r
994                                 pmLVFindInfo = (LVFINDINFOA*)lParam;\r
995                                 wLVFindInfo.flags = pmLVFindInfo->flags;\r
996                                 if(pmLVFindInfo->flags & (LVFI_STRING | LVFI_PARTIAL))\r
997                                 {\r
998                                         pw0 = DuplicateMtoW(pmLVFindInfo->psz, -1);\r
999                                         wLVFindInfo.psz = pw0;\r
1000                                 }\r
1001                                 wLVFindInfo.lParam = pmLVFindInfo->lParam;\r
1002                                 wLVFindInfo.pt = pmLVFindInfo->pt;\r
1003                                 wLVFindInfo.vkDirection = pmLVFindInfo->vkDirection;\r
1004                                 r = SendMessageW(hWnd, LVM_FINDITEMW, wParam, (LPARAM)&wLVItem);\r
1005                                 break;\r
1006                         case LVM_GETCOLUMNA:\r
1007                                 pmLVColumn = (LVCOLUMNA*)lParam;\r
1008                                 wLVColumn.mask = pmLVColumn->mask;\r
1009                                 wLVColumn.fmt = pmLVColumn->fmt;\r
1010                                 wLVColumn.cx = pmLVColumn->cx;\r
1011                                 Size = pmLVColumn->cchTextMax * 4;\r
1012                                 if(pmLVColumn->mask & LVCF_TEXT)\r
1013                                 {\r
1014                                         pw0 = AllocateStringW(Size);\r
1015                                         wLVColumn.pszText = pw0;\r
1016                                         wLVColumn.cchTextMax = Size;\r
1017                                 }\r
1018                                 wLVColumn.iSubItem = pmLVColumn->iSubItem;\r
1019                                 wLVColumn.iImage = pmLVColumn->iImage;\r
1020                                 wLVColumn.iOrder = pmLVColumn->iOrder;\r
1021                                 r = SendMessageW(hWnd, LVM_GETCOLUMNW, wParam, (LPARAM)&wLVColumn);\r
1022                                 pmLVColumn->mask = wLVColumn.mask;\r
1023                                 pmLVColumn->fmt = wLVColumn.fmt;\r
1024                                 pmLVColumn->cx = wLVColumn.cx;\r
1025                                 if(pmLVColumn->mask & LVCF_TEXT)\r
1026                                 {\r
1027                                         WtoM(pmLVColumn->pszText, pmLVColumn->cchTextMax, wLVColumn.pszText, -1);\r
1028                                         TerminateStringM(pmLVColumn->pszText, pmLVColumn->cchTextMax);\r
1029                                 }\r
1030                                 pmLVColumn->iSubItem = wLVColumn.iSubItem;\r
1031                                 pmLVColumn->iImage = wLVColumn.iImage;\r
1032                                 pmLVColumn->iOrder = wLVColumn.iOrder;\r
1033                                 break;\r
1034                         case LVM_INSERTCOLUMNA:\r
1035                                 pmLVColumn = (LVCOLUMNA*)lParam;\r
1036                                 wLVColumn.mask = pmLVColumn->mask;\r
1037                                 wLVColumn.fmt = pmLVColumn->fmt;\r
1038                                 wLVColumn.cx = pmLVColumn->cx;\r
1039                                 if(pmLVColumn->mask & LVCF_TEXT)\r
1040                                 {\r
1041                                         pw0 = DuplicateMtoW(pmLVColumn->pszText, -1);\r
1042                                         wLVColumn.pszText = pw0;\r
1043                                         // TODO: cchTextMaxの確認\r
1044                                         wLVColumn.cchTextMax = pmLVColumn->cchTextMax;\r
1045                                 }\r
1046                                 wLVColumn.iSubItem = pmLVColumn->iSubItem;\r
1047                                 wLVColumn.iImage = pmLVColumn->iImage;\r
1048                                 wLVColumn.iOrder = pmLVColumn->iOrder;\r
1049                                 r = SendMessageW(hWnd, LVM_INSERTCOLUMNW, wParam, (LPARAM)&wLVColumn);\r
1050                                 break;\r
1051                         case LVM_GETITEMTEXTA:\r
1052                                 pmLVItem = (LVITEMA*)lParam;\r
1053                                 wLVItem.mask = pmLVItem->mask;\r
1054                                 wLVItem.iItem = pmLVItem->iItem;\r
1055                                 wLVItem.iSubItem = pmLVItem->iSubItem;\r
1056                                 wLVItem.state = pmLVItem->state;\r
1057                                 wLVItem.stateMask = pmLVItem->stateMask;\r
1058                                 Size = pmLVItem->cchTextMax * 4;\r
1059                                 pw0 = AllocateStringW(Size);\r
1060                                 wLVItem.pszText = pw0;\r
1061                                 wLVItem.cchTextMax = Size;\r
1062                                 wLVItem.iImage = pmLVItem->iImage;\r
1063                                 wLVItem.lParam = pmLVItem->lParam;\r
1064                                 wLVItem.iIndent = pmLVItem->iIndent;\r
1065                                 r = SendMessageW(hWnd, LVM_GETITEMTEXTW, wParam, (LPARAM)&wLVItem);\r
1066                                 pmLVItem->mask = wLVItem.mask;\r
1067                                 pmLVItem->iItem = wLVItem.iItem;\r
1068                                 pmLVItem->iSubItem = wLVItem.iSubItem;\r
1069                                 pmLVItem->state = wLVItem.state;\r
1070                                 pmLVItem->stateMask = wLVItem.stateMask;\r
1071                                 WtoM(pmLVItem->pszText, pmLVItem->cchTextMax, wLVItem.pszText, -1);\r
1072                                 TerminateStringM(pmLVItem->pszText, pmLVItem->cchTextMax);\r
1073                                 pmLVItem->iImage = wLVItem.iImage;\r
1074                                 pmLVItem->lParam = wLVItem.lParam;\r
1075                                 pmLVItem->iIndent = wLVItem.iIndent;\r
1076                                 break;\r
1077                         default:\r
1078                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
1079                                 break;\r
1080                         }\r
1081                 }\r
1082                 else if(_wcsicmp(ClassName, STATUSCLASSNAMEW) == 0)\r
1083                 {\r
1084                         switch(Msg)\r
1085                         {\r
1086                         case SB_SETTEXTA:\r
1087                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
1088                                 r = SendMessageW(hWnd, SB_SETTEXTW, wParam, (LPARAM)pw0);\r
1089                                 break;\r
1090                         default:\r
1091                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
1092                                 break;\r
1093                         }\r
1094                 }\r
1095                 else if(_wcsicmp(ClassName, WC_TREEVIEWW) == 0)\r
1096                 {\r
1097                         switch(Msg)\r
1098                         {\r
1099                         case TVM_GETITEMA:\r
1100                                 pmTVItem = (TVITEMEXA*)lParam;\r
1101                                 wTVItem.mask = pmTVItem->mask;\r
1102                                 wTVItem.hItem = pmTVItem->hItem;\r
1103                                 wTVItem.state = pmTVItem->state;\r
1104                                 wTVItem.stateMask = pmTVItem->stateMask;\r
1105                                 if(pmTVItem->mask & TVIF_TEXT)\r
1106                                 {\r
1107                                         Size = pmTVItem->cchTextMax * 4;\r
1108                                         pw0 = AllocateStringW(Size);\r
1109                                         wTVItem.pszText = pw0;\r
1110                                         wTVItem.cchTextMax = Size;\r
1111                                 }\r
1112                                 wTVItem.iImage = pmTVItem->iImage;\r
1113                                 wTVItem.iSelectedImage = pmTVItem->iSelectedImage;\r
1114                                 wTVItem.cChildren = pmTVItem->cChildren;\r
1115                                 wTVItem.lParam = pmTVItem->lParam;\r
1116                                 wTVItem.iIntegral = pmTVItem->iIntegral;\r
1117 //                              wTVItem.uStateEx = pmTVItem->uStateEx;\r
1118 //                              wTVItem.hwnd = pmTVItem->hwnd;\r
1119 //                              wTVItem.iExpandedImage = pmTVItem->iExpandedImage;\r
1120 //                              wTVItem.iReserved = pmTVItem->iReserved;\r
1121                                 r = SendMessageW(hWnd, TVM_GETITEMW, wParam, (LPARAM)&wTVItem);\r
1122                                 pmTVItem->mask = wTVItem.mask;\r
1123                                 pmTVItem->hItem = wTVItem.hItem;\r
1124                                 pmTVItem->state = wTVItem.state;\r
1125                                 pmTVItem->stateMask = wTVItem.stateMask;\r
1126                                 if(pmTVItem->mask & TVIF_TEXT)\r
1127                                 {\r
1128                                         WtoM(pmTVItem->pszText, pmTVItem->cchTextMax, wTVItem.pszText, -1);\r
1129                                         TerminateStringM(pmTVItem->pszText, pmTVItem->cchTextMax);\r
1130                                 }\r
1131                                 pmTVItem->iImage = wTVItem.iImage;\r
1132                                 pmTVItem->iSelectedImage = wTVItem.iSelectedImage;\r
1133                                 pmTVItem->cChildren = wTVItem.cChildren;\r
1134                                 pmTVItem->lParam = wTVItem.lParam;\r
1135                                 pmTVItem->iIntegral = wTVItem.iIntegral;\r
1136 //                              pmTVItem->uStateEx = wTVItem.uStateEx;\r
1137 //                              pmTVItem->hwnd = wTVItem.hwnd;\r
1138 //                              pmTVItem->iExpandedImage = wTVItem.iExpandedImage;\r
1139 //                              pmTVItem->iReserved = wTVItem.iReserved;\r
1140                                 break;\r
1141                         case TVM_INSERTITEMA:\r
1142                                 pmTVInsert = (TVINSERTSTRUCTA*)lParam;\r
1143                                 wTVInsert.hParent = pmTVInsert->hParent;\r
1144                                 wTVInsert.hInsertAfter = pmTVInsert->hInsertAfter;\r
1145                                 wTVInsert.itemex.mask = pmTVInsert->itemex.mask;\r
1146                                 wTVInsert.itemex.hItem = pmTVInsert->itemex.hItem;\r
1147                                 wTVInsert.itemex.state = pmTVInsert->itemex.state;\r
1148                                 wTVInsert.itemex.stateMask = pmTVInsert->itemex.stateMask;\r
1149                                 if(pmTVInsert->itemex.mask & TVIF_TEXT)\r
1150                                 {\r
1151                                         pw0 = DuplicateMtoW(pmTVInsert->itemex.pszText, -1);\r
1152                                         wTVInsert.itemex.pszText = pw0;\r
1153                                         // TODO: cchTextMaxの確認\r
1154                                         wTVInsert.itemex.cchTextMax = pmTVInsert->itemex.cchTextMax;\r
1155                                 }\r
1156                                 wTVInsert.itemex.iImage = pmTVInsert->itemex.iImage;\r
1157                                 wTVInsert.itemex.iSelectedImage = pmTVInsert->itemex.iSelectedImage;\r
1158                                 wTVInsert.itemex.cChildren = pmTVInsert->itemex.cChildren;\r
1159                                 wTVInsert.itemex.lParam = pmTVInsert->itemex.lParam;\r
1160                                 wTVInsert.itemex.iIntegral = pmTVInsert->itemex.iIntegral;\r
1161 //                              wTVInsert.itemex.uStateEx = pmTVInsert->itemex.uStateEx;\r
1162 //                              wTVInsert.itemex.hwnd = pmTVInsert->itemex.hwnd;\r
1163 //                              wTVInsert.itemex.iExpandedImage = pmTVInsert->itemex.iExpandedImage;\r
1164 //                              wTVInsert.itemex.iReserved = pmTVInsert->itemex.iReserved;\r
1165                                 r = SendMessageW(hWnd, TVM_INSERTITEMW, wParam, (LPARAM)&wTVInsert);\r
1166                                 break;\r
1167                         default:\r
1168                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
1169                                 break;\r
1170                         }\r
1171                 }\r
1172                 else\r
1173                         r = SendMessageW(hWnd, Msg, wParam, lParam);\r
1174                 break;\r
1175         }\r
1176 END_ROUTINE\r
1177         FreeDuplicatedString(pw0);\r
1178         FreeDuplicatedString(pw1);\r
1179         return r;\r
1180 }\r
1181 \r
1182 LRESULT DefDlgProcM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)\r
1183 {\r
1184         LRESULT r = 0;\r
1185 START_ROUTINE\r
1186         // WNDPROCがShift_JIS用であるため\r
1187         if(IsWindowUnicode(hWnd))\r
1188                 r = DefDlgProcW(hWnd, Msg, wParam, lParam);\r
1189         else\r
1190                 r = DefDlgProcA(hWnd, Msg, wParam, lParam);\r
1191 END_ROUTINE\r
1192         return r;\r
1193 }\r
1194 \r
1195 LRESULT SendDlgItemMessageM(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam)\r
1196 {\r
1197         LRESULT r = 0;\r
1198 START_ROUTINE\r
1199         r = SendMessageM(GetDlgItem(hDlg, nIDDlgItem), Msg, wParam, lParam);\r
1200 END_ROUTINE\r
1201         return r;\r
1202 }\r
1203 \r
1204 BOOL SetWindowTextM(HWND hWnd, LPCSTR lpString)\r
1205 {\r
1206         BOOL r = FALSE;\r
1207         wchar_t* pw0 = NULL;\r
1208 START_ROUTINE\r
1209         pw0 = DuplicateMtoW(lpString, -1);\r
1210         r = SetWindowTextW(hWnd, pw0);\r
1211 END_ROUTINE\r
1212         FreeDuplicatedString(pw0);\r
1213         return r;\r
1214 }\r
1215 \r
1216 UINT DragQueryFileM(HDROP hDrop, UINT iFile, LPSTR lpszFile, UINT cch)\r
1217 {\r
1218         UINT r = 0;\r
1219         wchar_t* pw0 = NULL;\r
1220 START_ROUTINE\r
1221         if(iFile == (UINT)-1)\r
1222                 r = DragQueryFileW(hDrop, iFile, (LPWSTR)lpszFile, cch);\r
1223         else\r
1224         {\r
1225                 pw0 = AllocateStringW(cch * 4);\r
1226                 DragQueryFileW(hDrop, iFile, pw0, cch * 4);\r
1227                 WtoM(lpszFile, cch, pw0, -1);\r
1228                 r = TerminateStringM(lpszFile, cch);\r
1229         }\r
1230 END_ROUTINE\r
1231         FreeDuplicatedString(pw0);\r
1232         return r;\r
1233 }\r
1234 \r
1235 LPSTR GetCommandLineM()\r
1236 {\r
1237         LPSTR r = 0;\r
1238         static char* pm0 = NULL;\r
1239 START_ROUTINE\r
1240         if(!pm0)\r
1241                 pm0 = DuplicateWtoM(GetCommandLineW(), -1);\r
1242         r = pm0;\r
1243 END_ROUTINE\r
1244         return r;\r
1245 }\r
1246 \r
1247 DWORD GetCurrentDirectoryM(DWORD nBufferLength, LPSTR lpBuffer)\r
1248 {\r
1249         DWORD r = 0;\r
1250         wchar_t* pw0 = NULL;\r
1251 START_ROUTINE\r
1252         // TODO: バッファが不十分な場合に必要なサイズを返す\r
1253         pw0 = AllocateStringW(nBufferLength * 4);\r
1254         GetCurrentDirectoryW(nBufferLength * 4, pw0);\r
1255         WtoM(lpBuffer, nBufferLength, pw0, -1);\r
1256         r = TerminateStringM(lpBuffer, nBufferLength);\r
1257 END_ROUTINE\r
1258         FreeDuplicatedString(pw0);\r
1259         return r;\r
1260 }\r
1261 \r
1262 BOOL SetCurrentDirectoryM(LPCSTR lpPathName)\r
1263 {\r
1264         BOOL r = FALSE;\r
1265         wchar_t* pw0 = NULL;\r
1266 START_ROUTINE\r
1267         pw0 = DuplicateMtoW(lpPathName, -1);\r
1268         r = SetCurrentDirectoryW(pw0);\r
1269 END_ROUTINE\r
1270         FreeDuplicatedString(pw0);\r
1271         return r;\r
1272 }\r
1273 \r
1274 DWORD GetTempPathM(DWORD nBufferLength, LPSTR lpBuffer)\r
1275 {\r
1276         DWORD r = 0;\r
1277         wchar_t* pw0 = NULL;\r
1278 START_ROUTINE\r
1279         pw0 = AllocateStringW(nBufferLength * 4);\r
1280         GetTempPathW(nBufferLength * 4, pw0);\r
1281         WtoM(lpBuffer, nBufferLength, pw0, -1);\r
1282         r = TerminateStringM(lpBuffer, nBufferLength);\r
1283 END_ROUTINE\r
1284         FreeDuplicatedString(pw0);\r
1285         return r;\r
1286 }\r
1287 \r
1288 DWORD GetFileAttributesM(LPCSTR lpFileName)\r
1289 {\r
1290         DWORD r = FALSE;\r
1291         wchar_t* pw0 = NULL;\r
1292 START_ROUTINE\r
1293         pw0 = DuplicateMtoW(lpFileName, -1);\r
1294         r = GetFileAttributesW(pw0);\r
1295 END_ROUTINE\r
1296         FreeDuplicatedString(pw0);\r
1297         return r;\r
1298 }\r
1299 \r
1300 DWORD GetModuleFileNameM(HMODULE hModule, LPCH lpFilename, DWORD nSize)\r
1301 {\r
1302         DWORD r = 0;\r
1303         wchar_t* pw0 = NULL;\r
1304 START_ROUTINE\r
1305         pw0 = AllocateStringW(nSize * 4);\r
1306         GetModuleFileNameW(hModule, pw0, nSize * 4);\r
1307         WtoM(lpFilename, nSize, pw0, -1);\r
1308         r = TerminateStringM(lpFilename, nSize);\r
1309 END_ROUTINE\r
1310         FreeDuplicatedString(pw0);\r
1311         return r;\r
1312 }\r
1313 \r
1314 LSTATUS RegOpenKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)\r
1315 {\r
1316         LSTATUS r = 0;\r
1317         wchar_t* pw0 = NULL;\r
1318 START_ROUTINE\r
1319         pw0 = DuplicateMtoW(lpSubKey, -1);\r
1320         r = RegOpenKeyExW(hKey, pw0, ulOptions, samDesired, phkResult);\r
1321 END_ROUTINE\r
1322         FreeDuplicatedString(pw0);\r
1323         return r;\r
1324 }\r
1325 \r
1326 LSTATUS RegCreateKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass, DWORD dwOptions, REGSAM samDesired, CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition)\r
1327 {\r
1328         LSTATUS r = 0;\r
1329         wchar_t* pw0 = NULL;\r
1330         wchar_t* pw1 = NULL;\r
1331 START_ROUTINE\r
1332         pw0 = DuplicateMtoW(lpSubKey, -1);\r
1333         pw1 = DuplicateMtoW(lpClass, -1);\r
1334         r = RegCreateKeyExW(hKey, pw0, Reserved, pw1, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition);\r
1335 END_ROUTINE\r
1336         FreeDuplicatedString(pw0);\r
1337         FreeDuplicatedString(pw1);\r
1338         return r;\r
1339 }\r
1340 \r
1341 LSTATUS RegDeleteValueM(HKEY hKey, LPCSTR lpValueName)\r
1342 {\r
1343         LSTATUS r = 0;\r
1344         wchar_t* pw0 = NULL;\r
1345 START_ROUTINE\r
1346         pw0 = DuplicateMtoW(lpValueName, -1);\r
1347         r = RegDeleteValueW(hKey, pw0);\r
1348 END_ROUTINE\r
1349         FreeDuplicatedString(pw0);\r
1350         return r;\r
1351 }\r
1352 \r
1353 LSTATUS RegQueryValueExM(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)\r
1354 {\r
1355         LSTATUS r = 0;\r
1356         wchar_t* pw0 = NULL;\r
1357         wchar_t* pw1 = NULL;\r
1358         DWORD dwType;\r
1359         DWORD wcbData;\r
1360 START_ROUTINE\r
1361         pw0 = DuplicateMtoW(lpValueName, -1);\r
1362         if(RegQueryValueExW(hKey, pw0, NULL, &dwType, NULL, 0) == ERROR_SUCCESS)\r
1363         {\r
1364                 switch(dwType)\r
1365                 {\r
1366                 case REG_SZ:\r
1367                 case REG_EXPAND_SZ:\r
1368                 case REG_MULTI_SZ:\r
1369                         if(lpcbData)\r
1370                         {\r
1371                                 pw1 = AllocateStringW(*lpcbData / sizeof(char) * 4);\r
1372                                 wcbData = *lpcbData / sizeof(char) * 4;\r
1373                                 r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, (LPBYTE)pw1, &wcbData);\r
1374                                 if(lpData)\r
1375                                         *lpcbData = sizeof(char) * WtoM((char*)lpData, *lpcbData / sizeof(char), pw1, wcbData / sizeof(wchar_t));\r
1376                                 else\r
1377                                         *lpcbData = sizeof(char) * WtoM(NULL, 0, pw1, wcbData / sizeof(wchar_t));\r
1378                         }\r
1379                         break;\r
1380                 default:\r
1381                         r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, lpData, lpcbData);\r
1382                         break;\r
1383                 }\r
1384         }\r
1385         else\r
1386                 r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, lpData, lpcbData);\r
1387 END_ROUTINE\r
1388         FreeDuplicatedString(pw0);\r
1389         FreeDuplicatedString(pw1);\r
1390         return r;\r
1391 }\r
1392 \r
1393 LSTATUS RegSetValueExM(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE* lpData, DWORD cbData)\r
1394 {\r
1395         LSTATUS r = 0;\r
1396         wchar_t* pw0 = NULL;\r
1397         wchar_t* pw1 = NULL;\r
1398         DWORD wcbData;\r
1399 START_ROUTINE\r
1400         pw0 = DuplicateMtoW(lpValueName, -1);\r
1401         switch(dwType)\r
1402         {\r
1403         case REG_SZ:\r
1404         case REG_EXPAND_SZ:\r
1405         case REG_MULTI_SZ:\r
1406                 wcbData = MtoW(NULL, 0, (char*)lpData, cbData / sizeof(char));\r
1407                 pw1 = AllocateStringW(wcbData);\r
1408                 MtoW(pw1, wcbData, (char*)lpData, cbData / sizeof(char));\r
1409                 wcbData = sizeof(wchar_t) * wcbData;\r
1410                 lpData = (BYTE*)pw1;\r
1411                 cbData = wcbData;\r
1412                 break;\r
1413         }\r
1414         r = RegSetValueExW(hKey, pw0, Reserved, dwType, lpData, cbData);\r
1415 END_ROUTINE\r
1416         FreeDuplicatedString(pw0);\r
1417         FreeDuplicatedString(pw1);\r
1418         return r;\r
1419 }\r
1420 \r
1421 BOOL TextOutM(HDC hdc, int x, int y, LPCSTR lpString, int c)\r
1422 {\r
1423         BOOL r = FALSE;\r
1424         wchar_t* pw0 = NULL;\r
1425 START_ROUTINE\r
1426         pw0 = DuplicateMtoW(lpString, c);\r
1427         r = TextOutW(hdc, x, y, pw0, wcslen(pw0));\r
1428 END_ROUTINE\r
1429         FreeDuplicatedString(pw0);\r
1430         return r;\r
1431 }\r
1432 \r
1433 BOOL GetTextExtentPoint32M(HDC hdc, LPCSTR lpString, int c, LPSIZE psizl)\r
1434 {\r
1435         BOOL r = FALSE;\r
1436         wchar_t* pw0 = NULL;\r
1437 START_ROUTINE\r
1438         pw0 = DuplicateMtoW(lpString, c);\r
1439         r = GetTextExtentPoint32W(hdc, pw0, wcslen(pw0), psizl);\r
1440 END_ROUTINE\r
1441         FreeDuplicatedString(pw0);\r
1442         return r;\r
1443 }\r
1444 \r
1445 INT_PTR PropertySheetM(LPCPROPSHEETHEADERA v0)\r
1446 {\r
1447         INT_PTR r = 0;\r
1448         PROPSHEETHEADERW a0;\r
1449         PROPSHEETPAGEW* pwPage;\r
1450         UINT i;\r
1451 START_ROUTINE\r
1452         a0.dwSize = sizeof(PROPSHEETHEADERW);\r
1453         a0.dwFlags = v0->dwFlags;\r
1454         a0.hwndParent = v0->hwndParent;\r
1455         a0.hInstance = v0->hInstance;\r
1456         if(v0->dwFlags & PSH_USEICONID)\r
1457                 a0.pszIcon = DuplicateMtoW(v0->pszIcon, -1);\r
1458         else\r
1459                 a0.hIcon = v0->hIcon;\r
1460         a0.pszCaption = DuplicateMtoW(v0->pszCaption, -1);\r
1461         a0.nPages = v0->nPages;\r
1462         if(v0->dwFlags & PSH_USEPSTARTPAGE)\r
1463                 a0.pStartPage = DuplicateMtoW(v0->pStartPage, -1);\r
1464         else\r
1465                 a0.nStartPage = v0->nStartPage;\r
1466         if(v0->dwFlags & PSH_PROPSHEETPAGE)\r
1467         {\r
1468                 if(v0->ppsp && (pwPage = (PROPSHEETPAGEW*)malloc(sizeof(PROPSHEETPAGEW) * v0->nPages)))\r
1469                 {\r
1470                         for(i = 0; i < v0->nPages; i++)\r
1471                         {\r
1472                                 pwPage[i].dwSize = sizeof(PROPSHEETPAGEW);\r
1473                                 pwPage[i].dwFlags = v0->ppsp[i].dwFlags;\r
1474                                 pwPage[i].hInstance = v0->ppsp[i].hInstance;\r
1475                                 if(v0->ppsp[i].dwFlags & PSP_DLGINDIRECT)\r
1476                                         pwPage[i].pResource = v0->ppsp[i].pResource;\r
1477                                 else\r
1478                                         pwPage[i].pszTemplate = DuplicateMtoW(v0->ppsp[i].pszTemplate, -1);\r
1479                                 if(v0->ppsp[i].dwFlags & PSP_USEICONID)\r
1480                                         pwPage[i].pszIcon = DuplicateMtoW(v0->ppsp[i].pszIcon, -1);\r
1481                                 else\r
1482                                         pwPage[i].hIcon = v0->ppsp[i].hIcon;\r
1483                                 if(v0->ppsp[i].dwFlags & PSP_USETITLE)\r
1484                                         pwPage[i].pszTitle = DuplicateMtoW(v0->ppsp[i].pszTitle, -1);\r
1485                                 pwPage[i].pfnDlgProc = v0->ppsp[i].pfnDlgProc;\r
1486                                 pwPage[i].lParam = v0->ppsp[i].lParam;\r
1487                                 // TODO: pfnCallback\r
1488                                 pwPage[i].pfnCallback = (LPFNPSPCALLBACKW)v0->ppsp[i].pfnCallback;\r
1489                                 pwPage[i].pcRefParent = v0->ppsp[i].pcRefParent;\r
1490                                 if(v0->ppsp[i].dwFlags & PSP_USEHEADERTITLE)\r
1491                                         pwPage[i].pszHeaderTitle = DuplicateMtoW(v0->ppsp[i].pszHeaderTitle, -1);\r
1492                                 if(v0->ppsp[i].dwFlags & PSP_USEHEADERSUBTITLE)\r
1493                                         pwPage[i].pszHeaderSubTitle = DuplicateMtoW(v0->ppsp[i].pszHeaderSubTitle, -1);\r
1494                         }\r
1495                 }\r
1496                 else\r
1497                         pwPage = NULL;\r
1498                 a0.ppsp = pwPage;\r
1499         }\r
1500         else\r
1501                 a0.phpage = v0->phpage;\r
1502         a0.pfnCallback = v0->pfnCallback;\r
1503         if(v0->dwFlags & PSH_USEHBMWATERMARK)\r
1504                 a0.hbmWatermark = v0->hbmWatermark;\r
1505         else\r
1506                 a0.pszbmWatermark = DuplicateMtoW(v0->pszbmWatermark, -1);\r
1507         r = PropertySheetW(&a0);\r
1508         if(a0.dwFlags & PSH_USEICONID)\r
1509                 FreeDuplicatedString((void*)a0.pszIcon);\r
1510         FreeDuplicatedString((void*)a0.pszCaption);\r
1511         if(v0->dwFlags & PSH_USEPSTARTPAGE)\r
1512                 FreeDuplicatedString((void*)a0.pStartPage);\r
1513         if(v0->dwFlags & PSH_PROPSHEETPAGE)\r
1514         {\r
1515                 if(pwPage)\r
1516                 {\r
1517                         for(i = 0; i < v0->nPages; i++)\r
1518                         {\r
1519                                 if(!(v0->ppsp[i].dwFlags & PSP_DLGINDIRECT))\r
1520                                         FreeDuplicatedString((void*)pwPage[i].pszTemplate);\r
1521                                 if(v0->ppsp[i].dwFlags & PSP_USEICONID)\r
1522                                         FreeDuplicatedString((void*)pwPage[i].pszIcon);\r
1523                                 if(v0->ppsp[i].dwFlags & PSP_USETITLE)\r
1524                                         FreeDuplicatedString((void*)pwPage[i].pszTitle);\r
1525                                 if(v0->ppsp[i].dwFlags & PSP_USEHEADERTITLE)\r
1526                                         FreeDuplicatedString((void*)pwPage[i].pszHeaderTitle);\r
1527                                 if(v0->ppsp[i].dwFlags & PSP_USEHEADERSUBTITLE)\r
1528                                         FreeDuplicatedString((void*)pwPage[i].pszHeaderSubTitle);\r
1529                         }\r
1530                         free(pwPage);\r
1531                 }\r
1532         }\r
1533         if(!(v0->dwFlags & PSH_USEHBMWATERMARK))\r
1534                 FreeDuplicatedString((void*)a0.pszbmWatermark);\r
1535 END_ROUTINE\r
1536         return r;\r
1537 }\r
1538 \r
1539 BOOL GetOpenFileNameM(LPOPENFILENAMEA v0)\r
1540 {\r
1541         BOOL r = FALSE;\r
1542         wchar_t* pw0 = NULL;\r
1543         wchar_t* pw1 = NULL;\r
1544         wchar_t* pw2 = NULL;\r
1545         wchar_t* pw3 = NULL;\r
1546         wchar_t* pw4 = NULL;\r
1547         wchar_t* pw5 = NULL;\r
1548         wchar_t* pw6 = NULL;\r
1549         wchar_t* pw7 = NULL;\r
1550         wchar_t* pw8 = NULL;\r
1551         wchar_t* pw9 = NULL;\r
1552         OPENFILENAMEW wofn;\r
1553 START_ROUTINE\r
1554         wofn.lStructSize = sizeof(OPENFILENAMEW);\r
1555         wofn.hwndOwner = v0->hwndOwner;\r
1556         wofn.hInstance = v0->hInstance;\r
1557         pw0 = DuplicateMtoWMultiString(v0->lpstrFilter);\r
1558         wofn.lpstrFilter = pw0;\r
1559         pw1 = DuplicateMtoWBuffer(v0->lpstrCustomFilter, -1, v0->nMaxCustFilter * 4);\r
1560         wofn.lpstrCustomFilter = pw1;\r
1561         wofn.nMaxCustFilter = v0->nMaxCustFilter * 4;\r
1562         wofn.nFilterIndex = v0->nFilterIndex;\r
1563         pw2 = DuplicateMtoWMultiStringBuffer(v0->lpstrFile, v0->nMaxFile * 4);\r
1564         wofn.lpstrFile = pw2;\r
1565         wofn.nMaxFile = v0->nMaxFile * 4;\r
1566         pw3 = DuplicateMtoWBuffer(v0->lpstrFileTitle, -1, v0->nMaxFileTitle * 4);\r
1567         wofn.lpstrFileTitle = pw3;\r
1568         wofn.nMaxFileTitle = v0->nMaxFileTitle * 4;\r
1569         pw4 = DuplicateMtoW(v0->lpstrInitialDir, -1);\r
1570         wofn.lpstrInitialDir = pw4;\r
1571         pw5 = DuplicateMtoW(v0->lpstrTitle, -1);\r
1572         wofn.lpstrTitle = pw5;\r
1573         wofn.Flags = v0->Flags;\r
1574         wofn.nFileOffset = MtoW(NULL, 0, v0->lpstrFile, v0->nFileOffset);\r
1575         wofn.nFileExtension = MtoW(NULL, 0, v0->lpstrFile, v0->nFileExtension);\r
1576         pw6 = DuplicateMtoW(v0->lpstrDefExt, -1);\r
1577         wofn.lpstrDefExt = pw6;\r
1578         wofn.lCustData = v0->lCustData;\r
1579         wofn.lpfnHook = v0->lpfnHook;\r
1580         wofn.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);\r
1581         wofn.pvReserved = v0->pvReserved;\r
1582         wofn.FlagsEx = v0->FlagsEx;\r
1583         r = GetOpenFileNameW(&wofn);\r
1584         WtoM(v0->lpstrFile, v0->nMaxFile, wofn.lpstrFile, -1);\r
1585         TerminateStringM(v0->lpstrFile, v0->nMaxFile);\r
1586         v0->nFileOffset = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileOffset);\r
1587         v0->nFileExtension = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileExtension);\r
1588 END_ROUTINE\r
1589         FreeDuplicatedString(pw0);\r
1590         FreeDuplicatedString(pw1);\r
1591         FreeDuplicatedString(pw2);\r
1592         FreeDuplicatedString(pw3);\r
1593         FreeDuplicatedString(pw4);\r
1594         FreeDuplicatedString(pw5);\r
1595         FreeDuplicatedString(pw6);\r
1596         return r;\r
1597 }\r
1598 \r
1599 BOOL GetSaveFileNameM(LPOPENFILENAMEA v0)\r
1600 {\r
1601         BOOL r = FALSE;\r
1602         wchar_t* pw0 = NULL;\r
1603         wchar_t* pw1 = NULL;\r
1604         wchar_t* pw2 = NULL;\r
1605         wchar_t* pw3 = NULL;\r
1606         wchar_t* pw4 = NULL;\r
1607         wchar_t* pw5 = NULL;\r
1608         wchar_t* pw6 = NULL;\r
1609         wchar_t* pw7 = NULL;\r
1610         wchar_t* pw8 = NULL;\r
1611         wchar_t* pw9 = NULL;\r
1612         OPENFILENAMEW wofn;\r
1613 START_ROUTINE\r
1614         wofn.lStructSize = sizeof(OPENFILENAMEW);\r
1615         wofn.hwndOwner = v0->hwndOwner;\r
1616         wofn.hInstance = v0->hInstance;\r
1617         pw0 = DuplicateMtoWMultiString(v0->lpstrFilter);\r
1618         wofn.lpstrFilter = pw0;\r
1619         pw1 = DuplicateMtoWBuffer(v0->lpstrCustomFilter, -1, v0->nMaxCustFilter * 4);\r
1620         wofn.lpstrCustomFilter = pw1;\r
1621         wofn.nMaxCustFilter = v0->nMaxCustFilter * 4;\r
1622         wofn.nFilterIndex = v0->nFilterIndex;\r
1623         pw2 = DuplicateMtoWMultiStringBuffer(v0->lpstrFile, v0->nMaxFile * 4);\r
1624         wofn.lpstrFile = pw2;\r
1625         wofn.nMaxFile = v0->nMaxFile * 4;\r
1626         pw3 = DuplicateMtoWBuffer(v0->lpstrFileTitle, -1, v0->nMaxFileTitle * 4);\r
1627         wofn.lpstrFileTitle = pw3;\r
1628         wofn.nMaxFileTitle = v0->nMaxFileTitle * 4;\r
1629         pw4 = DuplicateMtoW(v0->lpstrInitialDir, -1);\r
1630         wofn.lpstrInitialDir = pw4;\r
1631         pw5 = DuplicateMtoW(v0->lpstrTitle, -1);\r
1632         wofn.lpstrTitle = pw5;\r
1633         wofn.Flags = v0->Flags;\r
1634         wofn.nFileOffset = MtoW(NULL, 0, v0->lpstrFile, v0->nFileOffset);\r
1635         wofn.nFileExtension = MtoW(NULL, 0, v0->lpstrFile, v0->nFileExtension);\r
1636         pw6 = DuplicateMtoW(v0->lpstrDefExt, -1);\r
1637         wofn.lpstrDefExt = pw6;\r
1638         wofn.lCustData = v0->lCustData;\r
1639         wofn.lpfnHook = v0->lpfnHook;\r
1640         wofn.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);\r
1641         wofn.pvReserved = v0->pvReserved;\r
1642         wofn.FlagsEx = v0->FlagsEx;\r
1643         r = GetSaveFileNameW(&wofn);\r
1644         WtoM(v0->lpstrFile, v0->nMaxFile, wofn.lpstrFile, -1);\r
1645         TerminateStringM(v0->lpstrFile, v0->nMaxFile);\r
1646         v0->nFileOffset = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileOffset);\r
1647         v0->nFileExtension = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileExtension);\r
1648 END_ROUTINE\r
1649         FreeDuplicatedString(pw0);\r
1650         FreeDuplicatedString(pw1);\r
1651         FreeDuplicatedString(pw2);\r
1652         FreeDuplicatedString(pw3);\r
1653         FreeDuplicatedString(pw4);\r
1654         FreeDuplicatedString(pw5);\r
1655         FreeDuplicatedString(pw6);\r
1656         return r;\r
1657 }\r
1658 \r
1659 HWND HtmlHelpM(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData)\r
1660 {\r
1661         HWND r = NULL;\r
1662         wchar_t* pw0 = NULL;\r
1663 START_ROUTINE\r
1664         pw0 = DuplicateMtoW(pszFile, -1);\r
1665         r = HtmlHelpW(hwndCaller, pw0, uCommand, dwData);\r
1666 END_ROUTINE\r
1667         FreeDuplicatedString(pw0);\r
1668         return r;\r
1669 }\r
1670 \r
1671 BOOL CreateProcessM(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)\r
1672 {\r
1673         BOOL r = FALSE;\r
1674         wchar_t* pw0 = NULL;\r
1675         wchar_t* pw1 = NULL;\r
1676         wchar_t* pw2 = NULL;\r
1677         wchar_t* pw3 = NULL;\r
1678         wchar_t* pw4 = NULL;\r
1679         wchar_t* pw5 = NULL;\r
1680         STARTUPINFOW wStartupInfo;\r
1681 START_ROUTINE\r
1682         pw0 = DuplicateMtoW(lpApplicationName, -1);\r
1683         pw1 = DuplicateMtoWBuffer(lpCommandLine, -1, (strlen(lpCommandLine) + 1) * 4);\r
1684         pw2 = DuplicateMtoW(lpCurrentDirectory, -1);\r
1685         wStartupInfo.cb = sizeof(LPSTARTUPINFOW);\r
1686         pw3 = DuplicateMtoW(lpStartupInfo->lpReserved, -1);\r
1687         wStartupInfo.lpReserved = pw3;\r
1688         pw4 = DuplicateMtoW(lpStartupInfo->lpDesktop, -1);\r
1689         wStartupInfo.lpDesktop = pw4;\r
1690         pw5 = DuplicateMtoW(lpStartupInfo->lpTitle, -1);\r
1691         wStartupInfo.lpTitle = pw5;\r
1692         wStartupInfo.dwX = lpStartupInfo->dwX;\r
1693         wStartupInfo.dwY = lpStartupInfo->dwY;\r
1694         wStartupInfo.dwXSize = lpStartupInfo->dwXSize;\r
1695         wStartupInfo.dwYSize = lpStartupInfo->dwYSize;\r
1696         wStartupInfo.dwXCountChars = lpStartupInfo->dwXCountChars;\r
1697         wStartupInfo.dwYCountChars = lpStartupInfo->dwYCountChars;\r
1698         wStartupInfo.dwFillAttribute = lpStartupInfo->dwFillAttribute;\r
1699         wStartupInfo.dwFlags = lpStartupInfo->dwFlags;\r
1700         wStartupInfo.wShowWindow = lpStartupInfo->wShowWindow;\r
1701         wStartupInfo.cbReserved2 = lpStartupInfo->cbReserved2;\r
1702         wStartupInfo.lpReserved2 = lpStartupInfo->lpReserved2;\r
1703         wStartupInfo.hStdInput = lpStartupInfo->hStdInput;\r
1704         wStartupInfo.hStdOutput = lpStartupInfo->hStdOutput;\r
1705         wStartupInfo.hStdError = lpStartupInfo->hStdError;\r
1706         r = CreateProcessW(pw0, pw1, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, pw2, &wStartupInfo, lpProcessInformation);\r
1707         WtoM(lpCommandLine, strlen(lpCommandLine) + 1, pw1, -1);\r
1708 END_ROUTINE\r
1709         FreeDuplicatedString(pw0);\r
1710         FreeDuplicatedString(pw1);\r
1711         FreeDuplicatedString(pw2);\r
1712         FreeDuplicatedString(pw3);\r
1713         FreeDuplicatedString(pw4);\r
1714         FreeDuplicatedString(pw5);\r
1715         return r;\r
1716 }\r
1717 \r
1718 HINSTANCE FindExecutableM(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)\r
1719 {\r
1720         HINSTANCE r = NULL;\r
1721         wchar_t* pw0 = NULL;\r
1722         wchar_t* pw1 = NULL;\r
1723         wchar_t* pw2 = NULL;\r
1724         wchar_t* pw3 = NULL;\r
1725 START_ROUTINE\r
1726         pw0 = DuplicateMtoW(lpFile, -1);\r
1727         pw1 = DuplicateMtoW(lpDirectory, -1);\r
1728         pw2 = AllocateStringW(MAX_PATH * 4);\r
1729         r = FindExecutableW(pw0, pw1, pw2);\r
1730         // バッファ長不明のためオーバーランの可能性あり\r
1731         WtoM(lpResult, MAX_PATH, pw2, -1);\r
1732         TerminateStringM(lpResult, MAX_PATH);\r
1733 END_ROUTINE\r
1734         FreeDuplicatedString(pw0);\r
1735         FreeDuplicatedString(pw1);\r
1736         FreeDuplicatedString(pw2);\r
1737         FreeDuplicatedString(pw3);\r
1738         return r;\r
1739 }\r
1740 \r
1741 HINSTANCE ShellExecuteM(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd)\r
1742 {\r
1743         HINSTANCE r = NULL;\r
1744         wchar_t* pw0 = NULL;\r
1745         wchar_t* pw1 = NULL;\r
1746         wchar_t* pw2 = NULL;\r
1747         wchar_t* pw3 = NULL;\r
1748 START_ROUTINE\r
1749         pw0 = DuplicateMtoW(lpOperation, -1);\r
1750         pw1 = DuplicateMtoW(lpFile, -1);\r
1751         pw2 = DuplicateMtoW(lpParameters, -1);\r
1752         pw3 = DuplicateMtoW(lpDirectory, -1);\r
1753         r = ShellExecuteW(hwnd, pw0, pw1, pw2, pw3, nShowCmd);\r
1754 END_ROUTINE\r
1755         FreeDuplicatedString(pw0);\r
1756         FreeDuplicatedString(pw1);\r
1757         FreeDuplicatedString(pw2);\r
1758         FreeDuplicatedString(pw3);\r
1759         return r;\r
1760 }\r
1761 \r
1762 BOOL ShellExecuteExM(LPSHELLEXECUTEINFOA lpExecInfo)\r
1763 {\r
1764         BOOL r = FALSE;\r
1765         wchar_t* pw0 = NULL;\r
1766         wchar_t* pw1 = NULL;\r
1767         wchar_t* pw2 = NULL;\r
1768         wchar_t* pw3 = NULL;\r
1769         wchar_t* pw4 = NULL;\r
1770         SHELLEXECUTEINFOW wExecInfo;\r
1771 START_ROUTINE\r
1772         wExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);\r
1773         wExecInfo.fMask = lpExecInfo->fMask;\r
1774         wExecInfo.hwnd = lpExecInfo->hwnd;\r
1775         pw0 = DuplicateMtoW(lpExecInfo->lpVerb, -1);\r
1776         wExecInfo.lpVerb = pw0;\r
1777         pw1 = DuplicateMtoW(lpExecInfo->lpFile, -1);\r
1778         wExecInfo.lpFile = pw1;\r
1779         pw2 = DuplicateMtoW(lpExecInfo->lpParameters, -1);\r
1780         wExecInfo.lpParameters = pw2;\r
1781         pw3 = DuplicateMtoW(lpExecInfo->lpDirectory, -1);\r
1782         wExecInfo.lpDirectory = pw3;\r
1783         wExecInfo.nShow = lpExecInfo->nShow;\r
1784         wExecInfo.hInstApp = lpExecInfo->hInstApp;\r
1785         wExecInfo.lpIDList = lpExecInfo->lpIDList;\r
1786         if(lpExecInfo->fMask & SEE_MASK_CLASSNAME)\r
1787         {\r
1788                 pw4 = DuplicateMtoW(lpExecInfo->lpClass, -1);\r
1789                 wExecInfo.lpClass = pw4;\r
1790         }\r
1791         wExecInfo.hkeyClass = lpExecInfo->hkeyClass;\r
1792         wExecInfo.dwHotKey = lpExecInfo->dwHotKey;\r
1793         wExecInfo.hIcon = lpExecInfo->hIcon;\r
1794         wExecInfo.hProcess = lpExecInfo->hProcess;\r
1795         r = ShellExecuteExW(&wExecInfo);\r
1796         lpExecInfo->hInstApp = wExecInfo.hInstApp;\r
1797         lpExecInfo->hProcess = wExecInfo.hProcess;\r
1798 END_ROUTINE\r
1799         FreeDuplicatedString(pw0);\r
1800         FreeDuplicatedString(pw1);\r
1801         FreeDuplicatedString(pw2);\r
1802         FreeDuplicatedString(pw3);\r
1803         FreeDuplicatedString(pw4);\r
1804         return r;\r
1805 }\r
1806 \r
1807 PIDLIST_ABSOLUTE SHBrowseForFolderM(LPBROWSEINFOA lpbi)\r
1808 {\r
1809         PIDLIST_ABSOLUTE r = NULL;\r
1810         wchar_t* pw0 = NULL;\r
1811         wchar_t* pw1 = NULL;\r
1812         BROWSEINFOW wbi;\r
1813 START_ROUTINE\r
1814         wbi.hwndOwner = lpbi->hwndOwner;\r
1815         wbi.pidlRoot = lpbi->pidlRoot;\r
1816         pw0 = DuplicateMtoWBuffer(lpbi->pszDisplayName, -1, MAX_PATH * 4);\r
1817         wbi.pszDisplayName = pw0;\r
1818         pw1 = DuplicateMtoW(lpbi->lpszTitle, -1);\r
1819         wbi.lpszTitle = pw1;\r
1820         wbi.ulFlags = lpbi->ulFlags;\r
1821         // TODO: lpfn\r
1822         wbi.lpfn = lpbi->lpfn;\r
1823         wbi.lParam = lpbi->lParam;\r
1824         wbi.iImage = lpbi->iImage;\r
1825         r = SHBrowseForFolderW(&wbi);\r
1826         // バッファ長不明のためオーバーランの可能性あり\r
1827         WtoM(lpbi->pszDisplayName, MAX_PATH, wbi.pszDisplayName, -1);\r
1828         lpbi->iImage = wbi.iImage;\r
1829 END_ROUTINE\r
1830         FreeDuplicatedString(pw0);\r
1831         FreeDuplicatedString(pw1);\r
1832         return r;\r
1833 }\r
1834 \r
1835 BOOL SHGetPathFromIDListM(PCIDLIST_ABSOLUTE pidl, LPSTR pszPath)\r
1836 {\r
1837         BOOL r = FALSE;\r
1838         wchar_t* pw0 = NULL;\r
1839 START_ROUTINE\r
1840         pw0 = AllocateStringW(MAX_PATH * 4);\r
1841         r = SHGetPathFromIDListW(pidl, pw0);\r
1842         // バッファ長不明のためオーバーランの可能性あり\r
1843         WtoM(pszPath, MAX_PATH, pw0, -1);\r
1844         TerminateStringM(pszPath, MAX_PATH);\r
1845 END_ROUTINE\r
1846         FreeDuplicatedString(pw0);\r
1847         return r;\r
1848 }\r
1849 \r
1850 int SHFileOperationM(LPSHFILEOPSTRUCTA lpFileOp)\r
1851 {\r
1852         int r = 0;\r
1853         wchar_t* pw0 = NULL;\r
1854         wchar_t* pw1 = NULL;\r
1855         wchar_t* pw2 = NULL;\r
1856         SHFILEOPSTRUCTW wFileOp;\r
1857 START_ROUTINE\r
1858         wFileOp.hwnd = lpFileOp->hwnd;\r
1859         wFileOp.wFunc = lpFileOp->wFunc;\r
1860         pw0 = DuplicateMtoWMultiString(lpFileOp->pFrom);\r
1861         wFileOp.pFrom = pw0;\r
1862         pw1 = DuplicateMtoWMultiString(lpFileOp->pTo);\r
1863         wFileOp.pTo = pw1;\r
1864         wFileOp.fFlags = lpFileOp->fFlags;\r
1865         wFileOp.fAnyOperationsAborted = lpFileOp->fAnyOperationsAborted;\r
1866         wFileOp.hNameMappings = lpFileOp->hNameMappings;\r
1867         if(lpFileOp->fFlags & FOF_SIMPLEPROGRESS)\r
1868                 pw2 = DuplicateMtoW(lpFileOp->lpszProgressTitle, -1);\r
1869         r = SHFileOperationW(&wFileOp);\r
1870         lpFileOp->fAnyOperationsAborted = wFileOp.fAnyOperationsAborted;\r
1871 END_ROUTINE\r
1872         FreeDuplicatedString(pw0);\r
1873         FreeDuplicatedString(pw1);\r
1874         FreeDuplicatedString(pw2);\r
1875         return r;\r
1876 }\r
1877 \r
1878 BOOL AppendMenuM(HMENU hMenu, UINT uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem)\r
1879 {\r
1880         int r = 0;\r
1881         wchar_t* pw0 = NULL;\r
1882 START_ROUTINE\r
1883         if(uFlags & (MF_BITMAP | MF_OWNERDRAW))\r
1884                 r = AppendMenuW(hMenu, uFlags, uIDNewItem, (LPCWSTR)lpNewItem);\r
1885         else\r
1886         {\r
1887                 pw0 = DuplicateMtoW(lpNewItem, -1);\r
1888                 r = AppendMenuW(hMenu, uFlags, uIDNewItem, pw0);\r
1889         }\r
1890 END_ROUTINE\r
1891         FreeDuplicatedString(pw0);\r
1892         return r;\r
1893 }\r
1894 \r
1895 BOOL GetMenuItemInfoM(HMENU hmenu, UINT item, BOOL fByPosition, LPMENUITEMINFOA lpmii)\r
1896 {\r
1897         BOOL r = FALSE;\r
1898         wchar_t* pw0 = NULL;\r
1899         MENUITEMINFOW wmii;\r
1900 START_ROUTINE\r
1901         wmii.cbSize = sizeof(MENUITEMINFOW);\r
1902         wmii.fMask = lpmii->fMask;\r
1903         wmii.fType = lpmii->fType;\r
1904         wmii.fState = lpmii->fState;\r
1905         wmii.wID = lpmii->wID;\r
1906         wmii.hSubMenu = lpmii->hSubMenu;\r
1907         wmii.hbmpChecked = lpmii->hbmpChecked;\r
1908         wmii.hbmpUnchecked = lpmii->hbmpUnchecked;\r
1909         wmii.dwItemData = lpmii->dwItemData;\r
1910         if(lpmii->fMask & MIIM_TYPE)\r
1911         {\r
1912                 pw0 = DuplicateMtoWBuffer(lpmii->dwTypeData, -1, lpmii->cch * 4);\r
1913                 wmii.dwTypeData = pw0;\r
1914                 wmii.cch = lpmii->cch * 4;\r
1915         }\r
1916         wmii.hbmpItem = lpmii->hbmpItem;\r
1917         r = GetMenuItemInfoW(hmenu, item, fByPosition, &wmii);\r
1918         lpmii->fType = wmii.fType;\r
1919         lpmii->fState = wmii.fState;\r
1920         lpmii->wID = wmii.wID;\r
1921         lpmii->hSubMenu = wmii.hSubMenu;\r
1922         lpmii->hbmpChecked = wmii.hbmpChecked;\r
1923         lpmii->hbmpUnchecked = wmii.hbmpUnchecked;\r
1924         lpmii->dwItemData = wmii.dwItemData;\r
1925         WtoM(lpmii->dwTypeData, lpmii->cch, wmii.dwTypeData, -1);\r
1926         TerminateStringM(lpmii->dwTypeData, lpmii->cch);\r
1927 END_ROUTINE\r
1928         FreeDuplicatedString(pw0);\r
1929         return r;\r
1930 }\r
1931 \r
1932 HFONT CreateFontIndirectM(CONST LOGFONTA *lplf)\r
1933 {\r
1934         HFONT r = NULL;\r
1935         LOGFONTW wlf;\r
1936 START_ROUTINE\r
1937         wlf.lfHeight = lplf->lfHeight;\r
1938         wlf.lfWidth = lplf->lfWidth;\r
1939         wlf.lfEscapement = lplf->lfEscapement;\r
1940         wlf.lfOrientation = lplf->lfOrientation;\r
1941         wlf.lfWeight = lplf->lfWeight;\r
1942         wlf.lfItalic = lplf->lfItalic;\r
1943         wlf.lfUnderline = lplf->lfUnderline;\r
1944         wlf.lfStrikeOut = lplf->lfStrikeOut;\r
1945         wlf.lfCharSet = lplf->lfCharSet;\r
1946         wlf.lfOutPrecision = lplf->lfOutPrecision;\r
1947         wlf.lfClipPrecision = lplf->lfClipPrecision;\r
1948         wlf.lfQuality = lplf->lfQuality;\r
1949         wlf.lfPitchAndFamily = lplf->lfPitchAndFamily;\r
1950         MtoW(wlf.lfFaceName, LF_FACESIZE, lplf->lfFaceName, -1);\r
1951         TerminateStringW(wlf.lfFaceName, LF_FACESIZE);\r
1952         r = CreateFontIndirect(&wlf);\r
1953 END_ROUTINE\r
1954         return r;\r
1955 }\r
1956 \r
1957 BOOL ChooseFontM(LPCHOOSEFONTA v0)\r
1958 {\r
1959         BOOL r = FALSE;\r
1960         wchar_t* pw0 = NULL;\r
1961         CHOOSEFONTW a0;\r
1962         LOGFONTW* pwlf;\r
1963 START_ROUTINE\r
1964         a0.lStructSize = sizeof(CHOOSEFONTW);\r
1965         a0.hwndOwner = v0->hwndOwner;\r
1966         a0.hDC = v0->hDC;\r
1967         if(v0->lpLogFont && (pwlf = (LOGFONTW*)malloc(sizeof(LOGFONTW))))\r
1968         {\r
1969                 pwlf->lfHeight = v0->lpLogFont->lfHeight;\r
1970                 pwlf->lfWidth = v0->lpLogFont->lfWidth;\r
1971                 pwlf->lfEscapement = v0->lpLogFont->lfEscapement;\r
1972                 pwlf->lfOrientation = v0->lpLogFont->lfOrientation;\r
1973                 pwlf->lfWeight = v0->lpLogFont->lfWeight;\r
1974                 pwlf->lfItalic = v0->lpLogFont->lfItalic;\r
1975                 pwlf->lfUnderline = v0->lpLogFont->lfUnderline;\r
1976                 pwlf->lfStrikeOut = v0->lpLogFont->lfStrikeOut;\r
1977                 pwlf->lfCharSet = v0->lpLogFont->lfCharSet;\r
1978                 pwlf->lfOutPrecision = v0->lpLogFont->lfOutPrecision;\r
1979                 pwlf->lfClipPrecision = v0->lpLogFont->lfClipPrecision;\r
1980                 pwlf->lfQuality = v0->lpLogFont->lfQuality;\r
1981                 pwlf->lfPitchAndFamily = v0->lpLogFont->lfPitchAndFamily;\r
1982                 MtoW(pwlf->lfFaceName, LF_FACESIZE, v0->lpLogFont->lfFaceName, -1);\r
1983                 TerminateStringW(pwlf->lfFaceName, LF_FACESIZE);\r
1984         }\r
1985         else\r
1986                 pwlf = NULL;\r
1987         a0.lpLogFont = pwlf;\r
1988         a0.iPointSize = v0->iPointSize;\r
1989         a0.Flags = v0->Flags;\r
1990         a0.rgbColors = v0->rgbColors;\r
1991         a0.lCustData = v0->lCustData;\r
1992         a0.lpfnHook = v0->lpfnHook;\r
1993         a0.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);\r
1994         a0.hInstance = v0->hInstance;\r
1995         a0.lpszStyle = DuplicateMtoWBuffer(v0->lpszStyle, -1, LF_FACESIZE * 4);\r
1996         a0.nFontType = v0->nFontType;\r
1997         a0.nSizeMin = v0->nSizeMin;\r
1998         a0.nSizeMax = v0->nSizeMax;\r
1999         r = ChooseFontW(&a0);\r
2000         if(v0->lpLogFont)\r
2001         {\r
2002                 v0->lpLogFont->lfHeight = pwlf->lfHeight;\r
2003                 v0->lpLogFont->lfWidth = pwlf->lfWidth;\r
2004                 v0->lpLogFont->lfEscapement = pwlf->lfEscapement;\r
2005                 v0->lpLogFont->lfOrientation = pwlf->lfOrientation;\r
2006                 v0->lpLogFont->lfWeight = pwlf->lfWeight;\r
2007                 v0->lpLogFont->lfItalic = pwlf->lfItalic;\r
2008                 v0->lpLogFont->lfUnderline = pwlf->lfUnderline;\r
2009                 v0->lpLogFont->lfStrikeOut = pwlf->lfStrikeOut;\r
2010                 v0->lpLogFont->lfCharSet = pwlf->lfCharSet;\r
2011                 v0->lpLogFont->lfOutPrecision = pwlf->lfOutPrecision;\r
2012                 v0->lpLogFont->lfClipPrecision = pwlf->lfClipPrecision;\r
2013                 v0->lpLogFont->lfQuality = pwlf->lfQuality;\r
2014                 v0->lpLogFont->lfPitchAndFamily = pwlf->lfPitchAndFamily;\r
2015                 WtoM(v0->lpLogFont->lfFaceName, LF_FACESIZE, pwlf->lfFaceName, -1);\r
2016                 TerminateStringM(v0->lpLogFont->lfFaceName, LF_FACESIZE);\r
2017         }\r
2018         v0->rgbColors = a0.rgbColors;\r
2019         WtoM(v0->lpszStyle, LF_FACESIZE, a0.lpszStyle, -1);\r
2020         TerminateStringM(v0->lpszStyle, LF_FACESIZE);\r
2021         v0->nFontType = a0.nFontType;\r
2022         if(pwlf)\r
2023                 free(pwlf);\r
2024         FreeDuplicatedString((void*)a0.lpTemplateName);\r
2025         FreeDuplicatedString(a0.lpszStyle);\r
2026 END_ROUTINE\r
2027         FreeDuplicatedString(pw0);\r
2028         return r;\r
2029 }\r
2030 \r
2031 INT_PTR DialogBoxParamM(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)\r
2032 {\r
2033         INT_PTR r = 0;\r
2034         wchar_t* pw0 = NULL;\r
2035 START_ROUTINE\r
2036         pw0 = DuplicateMtoW(lpTemplateName, -1);\r
2037         r = DialogBoxParamW(hInstance, pw0, hWndParent, lpDialogFunc, dwInitParam);\r
2038 END_ROUTINE\r
2039         FreeDuplicatedString(pw0);\r
2040         return r;\r
2041 }\r
2042 \r
2043 HWND CreateDialogParamM(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)\r
2044 {\r
2045         HWND r = NULL;\r
2046         wchar_t* pw0 = NULL;\r
2047 START_ROUTINE\r
2048         pw0 = DuplicateMtoW(lpTemplateName, -1);\r
2049         r = CreateDialogParamW(hInstance, pw0, hWndParent, lpDialogFunc, dwInitParam);\r
2050 END_ROUTINE\r
2051         FreeDuplicatedString(pw0);\r
2052         return r;\r
2053 }\r
2054 \r
2055 BOOL sndPlaySoundM(LPCSTR pszSound, UINT fuSound)\r
2056 {\r
2057         BOOL r = FALSE;\r
2058         wchar_t* pw0 = NULL;\r
2059 START_ROUTINE\r
2060         pw0 = DuplicateMtoW(pszSound, -1);\r
2061         r = sndPlaySoundW(pw0, fuSound);\r
2062 END_ROUTINE\r
2063         FreeDuplicatedString(pw0);\r
2064         return r;\r
2065 }\r
2066 \r
2067 HANDLE SetClipboardDataM(UINT uFormat, HANDLE hMem)\r
2068 {\r
2069         HANDLE r = NULL;\r
2070         char* p;\r
2071         int Length;\r
2072         int BufferLength;\r
2073         HGLOBAL hBufferMem;\r
2074 START_ROUTINE\r
2075         if(uFormat == CF_TEXT)\r
2076         {\r
2077                 p = (char*)GlobalLock(hMem);\r
2078                 Length = (int)GlobalSize(hMem);\r
2079                 BufferLength = MtoW(NULL, 0, p, Length);\r
2080                 if(hBufferMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * BufferLength))\r
2081                 {\r
2082                         MtoW((LPWSTR)GlobalLock(hBufferMem), BufferLength, p, Length);\r
2083                         GlobalUnlock(hBufferMem);\r
2084                         r = SetClipboardData(CF_UNICODETEXT, hBufferMem);\r
2085                 }\r
2086                 GlobalUnlock(hMem);\r
2087                 GlobalFree(hMem);\r
2088         }\r
2089         else\r
2090                 r = SetClipboardData(uFormat, hMem);\r
2091 END_ROUTINE\r
2092         return r;\r
2093 }\r
2094 \r
2095 BOOL CopyFileM(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExists)\r
2096 {\r
2097         BOOL r = FALSE;\r
2098         wchar_t* pw0 = NULL;\r
2099         wchar_t* pw1 = NULL;\r
2100 START_ROUTINE\r
2101         pw0 = DuplicateMtoW(lpExistingFileName, -1);\r
2102         pw1 = DuplicateMtoW(lpNewFileName, -1);\r
2103         r = CopyFileW(pw0, pw1, bFailIfExists);\r
2104 END_ROUTINE\r
2105         FreeDuplicatedString(pw0);\r
2106         FreeDuplicatedString(pw1);\r
2107         return r;\r
2108 }\r
2109 \r
2110 int mkdirM(const char * _Path)\r
2111 {\r
2112         int r = 0;\r
2113         wchar_t* pw0 = NULL;\r
2114 START_ROUTINE\r
2115         pw0 = DuplicateMtoW(_Path, -1);\r
2116         r = _wmkdir(pw0);\r
2117 END_ROUTINE\r
2118         FreeDuplicatedString(pw0);\r
2119         return r;\r
2120 }\r
2121 \r
2122 int _mkdirM(const char * _Path)\r
2123 {\r
2124         int r = 0;\r
2125         wchar_t* pw0 = NULL;\r
2126 START_ROUTINE\r
2127         pw0 = DuplicateMtoW(_Path, -1);\r
2128         r = _wmkdir(pw0);\r
2129 END_ROUTINE\r
2130         FreeDuplicatedString(pw0);\r
2131         return r;\r
2132 }\r
2133 \r
2134 int rmdirM(const char * _Path)\r
2135 {\r
2136         int r = 0;\r
2137         wchar_t* pw0 = NULL;\r
2138 START_ROUTINE\r
2139         pw0 = DuplicateMtoW(_Path, -1);\r
2140         r = _wrmdir(pw0);\r
2141 END_ROUTINE\r
2142         FreeDuplicatedString(pw0);\r
2143         return r;\r
2144 }\r
2145 \r
2146 int _rmdirM(const char * _Path)\r
2147 {\r
2148         int r = 0;\r
2149         wchar_t* pw0 = NULL;\r
2150 START_ROUTINE\r
2151         pw0 = DuplicateMtoW(_Path, -1);\r
2152         r = _wrmdir(pw0);\r
2153 END_ROUTINE\r
2154         FreeDuplicatedString(pw0);\r
2155         return r;\r
2156 }\r
2157 \r
2158 size_t _mbslenM(const unsigned char * _Str)\r
2159 {\r
2160         size_t r = 0;\r
2161 START_ROUTINE\r
2162         while(GetNextCharM(_Str, &_Str) > 0)\r
2163         {\r
2164                 r++;\r
2165         }\r
2166 END_ROUTINE\r
2167         return r;\r
2168 }\r
2169 \r
2170 unsigned char * _mbschrM(const unsigned char * _Str, unsigned int _Ch)\r
2171 {\r
2172         unsigned char* r = NULL;\r
2173         unsigned int c;\r
2174         unsigned char* p;\r
2175 START_ROUTINE\r
2176         while((c = GetNextCharM(_Str, &p)) > 0)\r
2177         {\r
2178                 if(c == _Ch)\r
2179                         break;\r
2180                 _Str = p;\r
2181         }\r
2182         if(c == _Ch)\r
2183                 r = (unsigned char*)_Str;\r
2184 END_ROUTINE\r
2185         return r;\r
2186 }\r
2187 \r
2188 unsigned char * _mbsrchrM(const unsigned char * _Str, unsigned int _Ch)\r
2189 {\r
2190         unsigned char* r = NULL;\r
2191         unsigned int c;\r
2192         unsigned char* p;\r
2193 START_ROUTINE\r
2194         while((c = GetNextCharM(_Str, &p)) > 0)\r
2195         {\r
2196                 if(c == _Ch)\r
2197                         r = (unsigned char*)_Str;\r
2198                 _Str = p;\r
2199         }\r
2200         if(c == _Ch)\r
2201                 r = (unsigned char*)_Str;\r
2202 END_ROUTINE\r
2203         return r;\r
2204 }\r
2205 \r
2206 unsigned char * _mbsstrM(const unsigned char * _Str, const unsigned char * _Substr)\r
2207 {\r
2208         unsigned char* r = NULL;\r
2209 START_ROUTINE\r
2210         r = strstr(_Str, _Substr);\r
2211 END_ROUTINE\r
2212         return r;\r
2213 }\r
2214 \r
2215 int _mbscmpM(const unsigned char * _Str1, const unsigned char * _Str2)\r
2216 {\r
2217         int r = 0;\r
2218 START_ROUTINE\r
2219         r = strcmp(_Str1, _Str2);\r
2220 END_ROUTINE\r
2221         return r;\r
2222 }\r
2223 \r
2224 int _mbsicmpM(const unsigned char * _Str1, const unsigned char * _Str2)\r
2225 {\r
2226         int r = 0;\r
2227 START_ROUTINE\r
2228         r = _stricmp(_Str1, _Str2);\r
2229 END_ROUTINE\r
2230         return r;\r
2231 }\r
2232 \r
2233 int _mbsncmpM(const unsigned char * _Str1, const unsigned char * _Str2, size_t _MaxCount)\r
2234 {\r
2235         int r = 0;\r
2236         DWORD c1;\r
2237         DWORD c2;\r
2238 START_ROUTINE\r
2239         c1 = 0;\r
2240         c2 = 0;\r
2241         while(_MaxCount > 0)\r
2242         {\r
2243                 c1 = GetNextCharM(_Str1, &_Str1);\r
2244                 c2 = GetNextCharM(_Str2, &_Str2);\r
2245                 if(c1 != c2)\r
2246                         break;\r
2247                 _MaxCount--;\r
2248                 if(c1 == 0 || c2 == 0)\r
2249                         break;\r
2250         }\r
2251         r = c1 - c2;\r
2252 END_ROUTINE\r
2253         return r;\r
2254 }\r
2255 \r
2256 unsigned char * _mbslwrM(unsigned char * _String)\r
2257 {\r
2258         unsigned char* r = NULL;\r
2259 START_ROUTINE\r
2260         r = _strlwr(_String);\r
2261 END_ROUTINE\r
2262         return r;\r
2263 }\r
2264 \r
2265 unsigned char * _mbsuprM(unsigned char * _String)\r
2266 {\r
2267         unsigned char* r = NULL;\r
2268 START_ROUTINE\r
2269         r = _strupr(_String);\r
2270 END_ROUTINE\r
2271         return r;\r
2272 }\r
2273 \r
2274 unsigned char * _mbsnincM(const unsigned char * _Str, size_t _Count)\r
2275 {\r
2276         unsigned char* r = NULL;\r
2277 START_ROUTINE\r
2278         while(_Count > 0 && GetNextCharM(_Str, &_Str) > 0)\r
2279         {\r
2280                 _Count--;\r
2281         }\r
2282         r = (unsigned char*)_Str;\r
2283 END_ROUTINE\r
2284         return r;\r
2285 }\r
2286 \r
2287 FILE * fopenM(const char * _Filename, const char * _Mode)\r
2288 {\r
2289         FILE* r = NULL;\r
2290         wchar_t* pw0 = NULL;\r
2291         wchar_t* pw1 = NULL;\r
2292 START_ROUTINE\r
2293         pw0 = DuplicateMtoW(_Filename, -1);\r
2294         pw1 = DuplicateMtoW(_Mode, -1);\r
2295         r = _wfopen(pw0, pw1);\r
2296 END_ROUTINE\r
2297         FreeDuplicatedString(pw0);\r
2298         FreeDuplicatedString(pw1);\r
2299         return r;\r
2300 }\r
2301 \r