OSDN Git Service

Enhance routines for extra commands.
[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         wchar_t* pw0 = NULL;\r
703         wchar_t* pw1 = NULL;\r
704         WNDCLASSEXW a0;\r
705 START_ROUTINE\r
706         a0.cbSize = sizeof(WNDCLASSEXW);\r
707         a0.style = v0->style;\r
708         a0.lpfnWndProc = v0->lpfnWndProc;\r
709         a0.cbClsExtra = v0->cbClsExtra;\r
710         a0.cbWndExtra = v0->cbWndExtra;\r
711         a0.hInstance = v0->hInstance;\r
712         a0.hIcon = v0->hIcon;\r
713         a0.hCursor = v0->hCursor;\r
714         a0.hbrBackground = v0->hbrBackground;\r
715         pw0 = DuplicateMtoW(v0->lpszMenuName, -1);\r
716         a0.lpszMenuName = pw0;\r
717         pw1 = DuplicateMtoW(v0->lpszClassName, -1);\r
718         a0.lpszClassName = pw1;\r
719         a0.hIconSm = v0->hIconSm;\r
720         r = RegisterClassExW(&a0);\r
721 END_ROUTINE\r
722         FreeDuplicatedString(pw0);\r
723         FreeDuplicatedString(pw1);\r
724         return r;\r
725 }\r
726 \r
727 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
728 {\r
729         HWND r = NULL;\r
730         wchar_t* pw0 = NULL;\r
731         wchar_t* pw1 = NULL;\r
732 START_ROUTINE\r
733         pw0 = DuplicateMtoW(lpClassName, -1);\r
734         pw1 = DuplicateMtoW(lpWindowName, -1);\r
735         r = CreateWindowExW(dwExStyle, pw0, pw1, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);\r
736 END_ROUTINE\r
737         FreeDuplicatedString(pw0);\r
738         FreeDuplicatedString(pw1);\r
739         return r;\r
740 }\r
741 \r
742 LONG GetWindowLongM(HWND hWnd, int nIndex)\r
743 {\r
744         LONG r = 0;\r
745 START_ROUTINE\r
746         if(IsWindowUnicode(hWnd))\r
747                 r = GetWindowLongW(hWnd, nIndex);\r
748         else\r
749                 r = GetWindowLongA(hWnd, nIndex);\r
750 END_ROUTINE\r
751         return r;\r
752 }\r
753 \r
754 LONG SetWindowLongM(HWND hWnd, int nIndex, LONG dwNewLong)\r
755 {\r
756         LONG r = 0;\r
757 START_ROUTINE\r
758         if(IsWindowUnicode(hWnd))\r
759                 r = SetWindowLongW(hWnd, nIndex, dwNewLong);\r
760         else\r
761                 r = SetWindowLongA(hWnd, nIndex, dwNewLong);\r
762 END_ROUTINE\r
763         return r;\r
764 }\r
765 \r
766 LONG_PTR GetWindowLongPtrM(HWND hWnd, int nIndex)\r
767 {\r
768         LONG_PTR r = 0;\r
769 START_ROUTINE\r
770         if(IsWindowUnicode(hWnd))\r
771                 r = GetWindowLongPtrW(hWnd, nIndex);\r
772         else\r
773                 r = GetWindowLongPtrA(hWnd, nIndex);\r
774 END_ROUTINE\r
775         return r;\r
776 }\r
777 \r
778 LONG_PTR SetWindowLongPtrM(HWND hWnd, int nIndex, LONG_PTR dwNewLong)\r
779 {\r
780         LONG_PTR r = 0;\r
781 START_ROUTINE\r
782         if(IsWindowUnicode(hWnd))\r
783                 r = SetWindowLongPtrW(hWnd, nIndex, dwNewLong);\r
784         else\r
785                 r = SetWindowLongPtrA(hWnd, nIndex, dwNewLong);\r
786 END_ROUTINE\r
787         return r;\r
788 }\r
789 \r
790 LRESULT DefWindowProcM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)\r
791 {\r
792         LRESULT r = 0;\r
793 START_ROUTINE\r
794         if(IsWindowUnicode(hWnd))\r
795                 r = DefWindowProcW(hWnd, Msg, wParam, lParam);\r
796         else\r
797                 r = DefWindowProcA(hWnd, Msg, wParam, lParam);\r
798 END_ROUTINE\r
799         return r;\r
800 }\r
801 \r
802 LRESULT CallWindowProcM(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)\r
803 {\r
804         LRESULT r = 0;\r
805 START_ROUTINE\r
806         if(IsWindowUnicode(hWnd))\r
807                 r = CallWindowProcW(lpPrevWndFunc, hWnd, Msg, wParam, lParam);\r
808         else\r
809                 r = CallWindowProcA(lpPrevWndFunc, hWnd, Msg, wParam, lParam);\r
810 END_ROUTINE\r
811         return r;\r
812 }\r
813 \r
814 LRESULT SendMessageM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)\r
815 {\r
816         LRESULT r = 0;\r
817         wchar_t* pw0 = NULL;\r
818         wchar_t* pw1 = NULL;\r
819         int Size;\r
820         LVITEMA* pmLVItem;\r
821         LVITEMW wLVItem;\r
822         LVFINDINFOA* pmLVFindInfo;\r
823         LVFINDINFOW wLVFindInfo;\r
824         LVCOLUMNA* pmLVColumn;\r
825         LVCOLUMNW wLVColumn;\r
826         TVITEMEXA* pmTVItem;\r
827         TVITEMEXW wTVItem;\r
828         TVINSERTSTRUCTA* pmTVInsert;\r
829         TVINSERTSTRUCTW wTVInsert;\r
830         wchar_t ClassName[MAX_PATH];\r
831 START_ROUTINE\r
832         switch(Msg)\r
833         {\r
834         case WM_SETTEXT:\r
835                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
836                 r = SendMessageW(hWnd, WM_SETTEXT, wParam, (LPARAM)pw0);\r
837                 break;\r
838         case WM_GETTEXT:\r
839                 pw0 = AllocateStringW(wParam * 4);\r
840                 SendMessageW(hWnd, WM_GETTEXT, wParam * 4, (LPARAM)pw0);\r
841                 WtoM((LPSTR)lParam, wParam, pw0, -1);\r
842                 r = TerminateStringM((LPSTR)lParam, wParam);\r
843                 break;\r
844         case WM_GETTEXTLENGTH:\r
845                 Size = SendMessageW(hWnd, WM_GETTEXTLENGTH, wParam, lParam) + 1;\r
846                 pw0 = AllocateStringW(Size);\r
847                 SendMessageW(hWnd, WM_GETTEXT, (WPARAM)Size, (LPARAM)pw0);\r
848                 r = WtoM(NULL, 0, pw0, -1) - 1;\r
849                 break;\r
850         default:\r
851                 GetClassNameW(hWnd, ClassName, sizeof(ClassName) / sizeof(wchar_t));\r
852                 if(_wcsicmp(ClassName, WC_EDITW) == 0)\r
853                 {\r
854                         switch(Msg)\r
855                         {\r
856                         case EM_REPLACESEL:\r
857                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
858                                 r = SendMessageW(hWnd, EM_REPLACESEL, wParam, (LPARAM)pw0);\r
859                                 break;\r
860                         default:\r
861                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
862                                 break;\r
863                         }\r
864                 }\r
865                 else if(_wcsicmp(ClassName, WC_COMBOBOXW) == 0)\r
866                 {\r
867                         switch(Msg)\r
868                         {\r
869                         case CB_ADDSTRING:\r
870                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
871                                 r = SendMessageW(hWnd, CB_ADDSTRING, wParam, (LPARAM)pw0);\r
872                                 break;\r
873                         case CB_GETLBTEXT:\r
874                                 Size = SendMessageW(hWnd, CB_GETLBTEXTLEN, wParam, 0) + 1;\r
875                                 pw0 = AllocateStringW(Size);\r
876                                 SendMessageW(hWnd, CB_GETLBTEXT, wParam, (LPARAM)pw0);\r
877                                 // バッファ長不明のためオーバーランの可能性あり\r
878                                 WtoM((LPSTR)lParam, Size * 4, pw0, -1);\r
879                                 r = TerminateStringM((LPSTR)lParam, Size * 4);\r
880                                 break;\r
881                         case CB_GETLBTEXTLEN:\r
882                                 Size = SendMessageW(hWnd, CB_GETLBTEXTLEN, wParam, 0) + 1;\r
883                                 pw0 = AllocateStringW(Size);\r
884                                 SendMessageW(hWnd, WM_GETTEXT, wParam, (LPARAM)pw0);\r
885                                 r = WtoM(NULL, 0, pw0, -1) - 1;\r
886                                 break;\r
887                         case CB_INSERTSTRING:\r
888                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
889                                 r = SendMessageW(hWnd, CB_INSERTSTRING, wParam, (LPARAM)pw0);\r
890                                 break;\r
891                         case CB_FINDSTRINGEXACT:\r
892                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
893                                 r = SendMessageW(hWnd, CB_FINDSTRINGEXACT, wParam, (LPARAM)pw0);\r
894                                 break;\r
895                         default:\r
896                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
897                                 break;\r
898                         }\r
899                 }\r
900                 else if(_wcsicmp(ClassName, WC_LISTBOXW) == 0)\r
901                 {\r
902                         switch(Msg)\r
903                         {\r
904                         case LB_ADDSTRING:\r
905                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
906                                 r = SendMessageW(hWnd, LB_ADDSTRING, wParam, (LPARAM)pw0);\r
907                                 break;\r
908                         case LB_INSERTSTRING:\r
909                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
910                                 r = SendMessageW(hWnd, LB_INSERTSTRING, wParam, (LPARAM)pw0);\r
911                                 break;\r
912                         case LB_GETTEXT:\r
913                                 Size = SendMessageW(hWnd, LB_GETTEXTLEN, wParam, 0) + 1;\r
914                                 pw0 = AllocateStringW(Size);\r
915                                 SendMessageW(hWnd, LB_GETTEXT, wParam, (LPARAM)pw0);\r
916                                 // バッファ長不明のためオーバーランの可能性あり\r
917                                 WtoM((LPSTR)lParam, Size * 4, pw0, -1);\r
918                                 r = TerminateStringM((LPSTR)lParam, Size * 4);\r
919                                 break;\r
920                         case LB_GETTEXTLEN:\r
921                                 Size = SendMessageW(hWnd, LB_GETTEXTLEN, wParam, 0) + 1;\r
922                                 pw0 = AllocateStringW(Size);\r
923                                 SendMessageW(hWnd, WM_GETTEXT, wParam, (LPARAM)pw0);\r
924                                 r = WtoM(NULL, 0, pw0, -1) - 1;\r
925                                 break;\r
926                         default:\r
927                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
928                                 break;\r
929                         }\r
930                 }\r
931                 else if(_wcsicmp(ClassName, WC_LISTVIEWW) == 0)\r
932                 {\r
933                         switch(Msg)\r
934                         {\r
935                         case LVM_GETITEMA:\r
936                                 pmLVItem = (LVITEMA*)lParam;\r
937                                 wLVItem.mask = pmLVItem->mask;\r
938                                 wLVItem.iItem = pmLVItem->iItem;\r
939                                 wLVItem.iSubItem = pmLVItem->iSubItem;\r
940                                 wLVItem.state = pmLVItem->state;\r
941                                 wLVItem.stateMask = pmLVItem->stateMask;\r
942                                 if(pmLVItem->mask & LVIF_TEXT)\r
943                                 {\r
944                                         Size = pmLVItem->cchTextMax * 4;\r
945                                         pw0 = AllocateStringW(Size);\r
946                                         wLVItem.pszText = pw0;\r
947                                         wLVItem.cchTextMax = Size;\r
948                                 }\r
949                                 wLVItem.iImage = pmLVItem->iImage;\r
950                                 wLVItem.lParam = pmLVItem->lParam;\r
951                                 wLVItem.iIndent = pmLVItem->iIndent;\r
952                                 r = SendMessageW(hWnd, LVM_GETITEMW, wParam, (LPARAM)&wLVItem);\r
953                                 pmLVItem->mask = wLVItem.mask;\r
954                                 pmLVItem->iItem = wLVItem.iItem;\r
955                                 pmLVItem->iSubItem = wLVItem.iSubItem;\r
956                                 pmLVItem->state = wLVItem.state;\r
957                                 pmLVItem->stateMask = wLVItem.stateMask;\r
958                                 if(pmLVItem->mask & LVIF_TEXT)\r
959                                 {\r
960                                         WtoM(pmLVItem->pszText, pmLVItem->cchTextMax, wLVItem.pszText, -1);\r
961                                         TerminateStringM(pmLVItem->pszText, pmLVItem->cchTextMax);\r
962                                 }\r
963                                 pmLVItem->iImage = wLVItem.iImage;\r
964                                 pmLVItem->lParam = wLVItem.lParam;\r
965                                 pmLVItem->iIndent = wLVItem.iIndent;\r
966                                 break;\r
967                         case LVM_SETITEMA:\r
968                                 pmLVItem = (LVITEMA*)lParam;\r
969                                 wLVItem.mask = pmLVItem->mask;\r
970                                 wLVItem.iItem = pmLVItem->iItem;\r
971                                 wLVItem.iSubItem = pmLVItem->iSubItem;\r
972                                 wLVItem.state = pmLVItem->state;\r
973                                 wLVItem.stateMask = pmLVItem->stateMask;\r
974                                 if(pmLVItem->mask & LVIF_TEXT)\r
975                                 {\r
976                                         pw0 = DuplicateMtoW(pmLVItem->pszText, -1);\r
977                                         wLVItem.pszText = pw0;\r
978                                         // TODO: cchTextMaxの確認\r
979                                         wLVItem.cchTextMax = pmLVItem->cchTextMax;\r
980                                 }\r
981                                 wLVItem.iImage = pmLVItem->iImage;\r
982                                 wLVItem.lParam = pmLVItem->lParam;\r
983                                 wLVItem.iIndent = pmLVItem->iIndent;\r
984                                 r = SendMessageW(hWnd, LVM_SETITEMW, wParam, (LPARAM)&wLVItem);\r
985                                 break;\r
986                         case LVM_INSERTITEMA:\r
987                                 pmLVItem = (LVITEMA*)lParam;\r
988                                 wLVItem.mask = pmLVItem->mask;\r
989                                 wLVItem.iItem = pmLVItem->iItem;\r
990                                 wLVItem.iSubItem = pmLVItem->iSubItem;\r
991                                 wLVItem.state = pmLVItem->state;\r
992                                 wLVItem.stateMask = pmLVItem->stateMask;\r
993                                 if(pmLVItem->mask & LVIF_TEXT)\r
994                                 {\r
995                                         pw0 = DuplicateMtoW(pmLVItem->pszText, -1);\r
996                                         wLVItem.pszText = pw0;\r
997                                         // TODO: cchTextMaxの確認\r
998                                         wLVItem.cchTextMax = pmLVItem->cchTextMax;\r
999                                 }\r
1000                                 wLVItem.iImage = pmLVItem->iImage;\r
1001                                 wLVItem.lParam = pmLVItem->lParam;\r
1002                                 wLVItem.iIndent = pmLVItem->iIndent;\r
1003                                 r = SendMessageW(hWnd, LVM_INSERTITEMW, wParam, (LPARAM)&wLVItem);\r
1004                                 break;\r
1005                         case LVM_FINDITEMA:\r
1006                                 pmLVFindInfo = (LVFINDINFOA*)lParam;\r
1007                                 wLVFindInfo.flags = pmLVFindInfo->flags;\r
1008                                 if(pmLVFindInfo->flags & (LVFI_STRING | LVFI_PARTIAL))\r
1009                                 {\r
1010                                         pw0 = DuplicateMtoW(pmLVFindInfo->psz, -1);\r
1011                                         wLVFindInfo.psz = pw0;\r
1012                                 }\r
1013                                 wLVFindInfo.lParam = pmLVFindInfo->lParam;\r
1014                                 wLVFindInfo.pt = pmLVFindInfo->pt;\r
1015                                 wLVFindInfo.vkDirection = pmLVFindInfo->vkDirection;\r
1016                                 r = SendMessageW(hWnd, LVM_FINDITEMW, wParam, (LPARAM)&wLVItem);\r
1017                                 break;\r
1018                         case LVM_GETCOLUMNA:\r
1019                                 pmLVColumn = (LVCOLUMNA*)lParam;\r
1020                                 wLVColumn.mask = pmLVColumn->mask;\r
1021                                 wLVColumn.fmt = pmLVColumn->fmt;\r
1022                                 wLVColumn.cx = pmLVColumn->cx;\r
1023                                 Size = pmLVColumn->cchTextMax * 4;\r
1024                                 if(pmLVColumn->mask & LVCF_TEXT)\r
1025                                 {\r
1026                                         pw0 = AllocateStringW(Size);\r
1027                                         wLVColumn.pszText = pw0;\r
1028                                         wLVColumn.cchTextMax = Size;\r
1029                                 }\r
1030                                 wLVColumn.iSubItem = pmLVColumn->iSubItem;\r
1031                                 wLVColumn.iImage = pmLVColumn->iImage;\r
1032                                 wLVColumn.iOrder = pmLVColumn->iOrder;\r
1033                                 r = SendMessageW(hWnd, LVM_GETCOLUMNW, wParam, (LPARAM)&wLVColumn);\r
1034                                 pmLVColumn->mask = wLVColumn.mask;\r
1035                                 pmLVColumn->fmt = wLVColumn.fmt;\r
1036                                 pmLVColumn->cx = wLVColumn.cx;\r
1037                                 if(pmLVColumn->mask & LVCF_TEXT)\r
1038                                 {\r
1039                                         WtoM(pmLVColumn->pszText, pmLVColumn->cchTextMax, wLVColumn.pszText, -1);\r
1040                                         TerminateStringM(pmLVColumn->pszText, pmLVColumn->cchTextMax);\r
1041                                 }\r
1042                                 pmLVColumn->iSubItem = wLVColumn.iSubItem;\r
1043                                 pmLVColumn->iImage = wLVColumn.iImage;\r
1044                                 pmLVColumn->iOrder = wLVColumn.iOrder;\r
1045                                 break;\r
1046                         case LVM_INSERTCOLUMNA:\r
1047                                 pmLVColumn = (LVCOLUMNA*)lParam;\r
1048                                 wLVColumn.mask = pmLVColumn->mask;\r
1049                                 wLVColumn.fmt = pmLVColumn->fmt;\r
1050                                 wLVColumn.cx = pmLVColumn->cx;\r
1051                                 if(pmLVColumn->mask & LVCF_TEXT)\r
1052                                 {\r
1053                                         pw0 = DuplicateMtoW(pmLVColumn->pszText, -1);\r
1054                                         wLVColumn.pszText = pw0;\r
1055                                         // TODO: cchTextMaxの確認\r
1056                                         wLVColumn.cchTextMax = pmLVColumn->cchTextMax;\r
1057                                 }\r
1058                                 wLVColumn.iSubItem = pmLVColumn->iSubItem;\r
1059                                 wLVColumn.iImage = pmLVColumn->iImage;\r
1060                                 wLVColumn.iOrder = pmLVColumn->iOrder;\r
1061                                 r = SendMessageW(hWnd, LVM_INSERTCOLUMNW, wParam, (LPARAM)&wLVColumn);\r
1062                                 break;\r
1063                         case LVM_GETITEMTEXTA:\r
1064                                 pmLVItem = (LVITEMA*)lParam;\r
1065                                 wLVItem.mask = pmLVItem->mask;\r
1066                                 wLVItem.iItem = pmLVItem->iItem;\r
1067                                 wLVItem.iSubItem = pmLVItem->iSubItem;\r
1068                                 wLVItem.state = pmLVItem->state;\r
1069                                 wLVItem.stateMask = pmLVItem->stateMask;\r
1070                                 Size = pmLVItem->cchTextMax * 4;\r
1071                                 pw0 = AllocateStringW(Size);\r
1072                                 wLVItem.pszText = pw0;\r
1073                                 wLVItem.cchTextMax = Size;\r
1074                                 wLVItem.iImage = pmLVItem->iImage;\r
1075                                 wLVItem.lParam = pmLVItem->lParam;\r
1076                                 wLVItem.iIndent = pmLVItem->iIndent;\r
1077                                 r = SendMessageW(hWnd, LVM_GETITEMTEXTW, wParam, (LPARAM)&wLVItem);\r
1078                                 pmLVItem->mask = wLVItem.mask;\r
1079                                 pmLVItem->iItem = wLVItem.iItem;\r
1080                                 pmLVItem->iSubItem = wLVItem.iSubItem;\r
1081                                 pmLVItem->state = wLVItem.state;\r
1082                                 pmLVItem->stateMask = wLVItem.stateMask;\r
1083                                 WtoM(pmLVItem->pszText, pmLVItem->cchTextMax, wLVItem.pszText, -1);\r
1084                                 TerminateStringM(pmLVItem->pszText, pmLVItem->cchTextMax);\r
1085                                 pmLVItem->iImage = wLVItem.iImage;\r
1086                                 pmLVItem->lParam = wLVItem.lParam;\r
1087                                 pmLVItem->iIndent = wLVItem.iIndent;\r
1088                                 break;\r
1089                         default:\r
1090                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
1091                                 break;\r
1092                         }\r
1093                 }\r
1094                 else if(_wcsicmp(ClassName, STATUSCLASSNAMEW) == 0)\r
1095                 {\r
1096                         switch(Msg)\r
1097                         {\r
1098                         case SB_SETTEXTA:\r
1099                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);\r
1100                                 r = SendMessageW(hWnd, SB_SETTEXTW, wParam, (LPARAM)pw0);\r
1101                                 break;\r
1102                         default:\r
1103                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
1104                                 break;\r
1105                         }\r
1106                 }\r
1107                 else if(_wcsicmp(ClassName, WC_TREEVIEWW) == 0)\r
1108                 {\r
1109                         switch(Msg)\r
1110                         {\r
1111                         case TVM_GETITEMA:\r
1112                                 pmTVItem = (TVITEMEXA*)lParam;\r
1113                                 wTVItem.mask = pmTVItem->mask;\r
1114                                 wTVItem.hItem = pmTVItem->hItem;\r
1115                                 wTVItem.state = pmTVItem->state;\r
1116                                 wTVItem.stateMask = pmTVItem->stateMask;\r
1117                                 if(pmTVItem->mask & TVIF_TEXT)\r
1118                                 {\r
1119                                         Size = pmTVItem->cchTextMax * 4;\r
1120                                         pw0 = AllocateStringW(Size);\r
1121                                         wTVItem.pszText = pw0;\r
1122                                         wTVItem.cchTextMax = Size;\r
1123                                 }\r
1124                                 wTVItem.iImage = pmTVItem->iImage;\r
1125                                 wTVItem.iSelectedImage = pmTVItem->iSelectedImage;\r
1126                                 wTVItem.cChildren = pmTVItem->cChildren;\r
1127                                 wTVItem.lParam = pmTVItem->lParam;\r
1128                                 wTVItem.iIntegral = pmTVItem->iIntegral;\r
1129 //                              wTVItem.uStateEx = pmTVItem->uStateEx;\r
1130 //                              wTVItem.hwnd = pmTVItem->hwnd;\r
1131 //                              wTVItem.iExpandedImage = pmTVItem->iExpandedImage;\r
1132 //                              wTVItem.iReserved = pmTVItem->iReserved;\r
1133                                 r = SendMessageW(hWnd, TVM_GETITEMW, wParam, (LPARAM)&wTVItem);\r
1134                                 pmTVItem->mask = wTVItem.mask;\r
1135                                 pmTVItem->hItem = wTVItem.hItem;\r
1136                                 pmTVItem->state = wTVItem.state;\r
1137                                 pmTVItem->stateMask = wTVItem.stateMask;\r
1138                                 if(pmTVItem->mask & TVIF_TEXT)\r
1139                                 {\r
1140                                         WtoM(pmTVItem->pszText, pmTVItem->cchTextMax, wTVItem.pszText, -1);\r
1141                                         TerminateStringM(pmTVItem->pszText, pmTVItem->cchTextMax);\r
1142                                 }\r
1143                                 pmTVItem->iImage = wTVItem.iImage;\r
1144                                 pmTVItem->iSelectedImage = wTVItem.iSelectedImage;\r
1145                                 pmTVItem->cChildren = wTVItem.cChildren;\r
1146                                 pmTVItem->lParam = wTVItem.lParam;\r
1147                                 pmTVItem->iIntegral = wTVItem.iIntegral;\r
1148 //                              pmTVItem->uStateEx = wTVItem.uStateEx;\r
1149 //                              pmTVItem->hwnd = wTVItem.hwnd;\r
1150 //                              pmTVItem->iExpandedImage = wTVItem.iExpandedImage;\r
1151 //                              pmTVItem->iReserved = wTVItem.iReserved;\r
1152                                 break;\r
1153                         case TVM_INSERTITEMA:\r
1154                                 pmTVInsert = (TVINSERTSTRUCTA*)lParam;\r
1155                                 wTVInsert.hParent = pmTVInsert->hParent;\r
1156                                 wTVInsert.hInsertAfter = pmTVInsert->hInsertAfter;\r
1157                                 wTVInsert.itemex.mask = pmTVInsert->itemex.mask;\r
1158                                 wTVInsert.itemex.hItem = pmTVInsert->itemex.hItem;\r
1159                                 wTVInsert.itemex.state = pmTVInsert->itemex.state;\r
1160                                 wTVInsert.itemex.stateMask = pmTVInsert->itemex.stateMask;\r
1161                                 if(pmTVInsert->itemex.mask & TVIF_TEXT)\r
1162                                 {\r
1163                                         pw0 = DuplicateMtoW(pmTVInsert->itemex.pszText, -1);\r
1164                                         wTVInsert.itemex.pszText = pw0;\r
1165                                         // TODO: cchTextMaxの確認\r
1166                                         wTVInsert.itemex.cchTextMax = pmTVInsert->itemex.cchTextMax;\r
1167                                 }\r
1168                                 wTVInsert.itemex.iImage = pmTVInsert->itemex.iImage;\r
1169                                 wTVInsert.itemex.iSelectedImage = pmTVInsert->itemex.iSelectedImage;\r
1170                                 wTVInsert.itemex.cChildren = pmTVInsert->itemex.cChildren;\r
1171                                 wTVInsert.itemex.lParam = pmTVInsert->itemex.lParam;\r
1172                                 wTVInsert.itemex.iIntegral = pmTVInsert->itemex.iIntegral;\r
1173 //                              wTVInsert.itemex.uStateEx = pmTVInsert->itemex.uStateEx;\r
1174 //                              wTVInsert.itemex.hwnd = pmTVInsert->itemex.hwnd;\r
1175 //                              wTVInsert.itemex.iExpandedImage = pmTVInsert->itemex.iExpandedImage;\r
1176 //                              wTVInsert.itemex.iReserved = pmTVInsert->itemex.iReserved;\r
1177                                 r = SendMessageW(hWnd, TVM_INSERTITEMW, wParam, (LPARAM)&wTVInsert);\r
1178                                 break;\r
1179                         default:\r
1180                                 r = SendMessageW(hWnd, Msg, wParam, lParam);\r
1181                                 break;\r
1182                         }\r
1183                 }\r
1184                 else\r
1185                         r = SendMessageW(hWnd, Msg, wParam, lParam);\r
1186                 break;\r
1187         }\r
1188 END_ROUTINE\r
1189         FreeDuplicatedString(pw0);\r
1190         FreeDuplicatedString(pw1);\r
1191         return r;\r
1192 }\r
1193 \r
1194 LRESULT DefDlgProcM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)\r
1195 {\r
1196         LRESULT r = 0;\r
1197 START_ROUTINE\r
1198         // WNDPROCがShift_JIS用であるため\r
1199         if(IsWindowUnicode(hWnd))\r
1200                 r = DefDlgProcW(hWnd, Msg, wParam, lParam);\r
1201         else\r
1202                 r = DefDlgProcA(hWnd, Msg, wParam, lParam);\r
1203 END_ROUTINE\r
1204         return r;\r
1205 }\r
1206 \r
1207 LRESULT SendDlgItemMessageM(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam)\r
1208 {\r
1209         LRESULT r = 0;\r
1210 START_ROUTINE\r
1211         r = SendMessageM(GetDlgItem(hDlg, nIDDlgItem), Msg, wParam, lParam);\r
1212 END_ROUTINE\r
1213         return r;\r
1214 }\r
1215 \r
1216 BOOL SetWindowTextM(HWND hWnd, LPCSTR lpString)\r
1217 {\r
1218         BOOL r = FALSE;\r
1219         wchar_t* pw0 = NULL;\r
1220 START_ROUTINE\r
1221         pw0 = DuplicateMtoW(lpString, -1);\r
1222         r = SetWindowTextW(hWnd, pw0);\r
1223 END_ROUTINE\r
1224         FreeDuplicatedString(pw0);\r
1225         return r;\r
1226 }\r
1227 \r
1228 UINT DragQueryFileM(HDROP hDrop, UINT iFile, LPSTR lpszFile, UINT cch)\r
1229 {\r
1230         UINT r = 0;\r
1231         wchar_t* pw0 = NULL;\r
1232 START_ROUTINE\r
1233         if(iFile == (UINT)-1)\r
1234                 r = DragQueryFileW(hDrop, iFile, (LPWSTR)lpszFile, cch);\r
1235         else\r
1236         {\r
1237                 pw0 = AllocateStringW(cch * 4);\r
1238                 DragQueryFileW(hDrop, iFile, pw0, cch * 4);\r
1239                 WtoM(lpszFile, cch, pw0, -1);\r
1240                 r = TerminateStringM(lpszFile, cch);\r
1241         }\r
1242 END_ROUTINE\r
1243         FreeDuplicatedString(pw0);\r
1244         return r;\r
1245 }\r
1246 \r
1247 LPSTR GetCommandLineM()\r
1248 {\r
1249         LPSTR r = 0;\r
1250         static char* pm0 = NULL;\r
1251 START_ROUTINE\r
1252         if(!pm0)\r
1253                 pm0 = DuplicateWtoM(GetCommandLineW(), -1);\r
1254         r = pm0;\r
1255 END_ROUTINE\r
1256         return r;\r
1257 }\r
1258 \r
1259 DWORD GetCurrentDirectoryM(DWORD nBufferLength, LPSTR lpBuffer)\r
1260 {\r
1261         DWORD r = 0;\r
1262         wchar_t* pw0 = NULL;\r
1263 START_ROUTINE\r
1264         // TODO: バッファが不十分な場合に必要なサイズを返す\r
1265         pw0 = AllocateStringW(nBufferLength * 4);\r
1266         GetCurrentDirectoryW(nBufferLength * 4, pw0);\r
1267         WtoM(lpBuffer, nBufferLength, pw0, -1);\r
1268         r = TerminateStringM(lpBuffer, nBufferLength);\r
1269 END_ROUTINE\r
1270         FreeDuplicatedString(pw0);\r
1271         return r;\r
1272 }\r
1273 \r
1274 BOOL SetCurrentDirectoryM(LPCSTR lpPathName)\r
1275 {\r
1276         BOOL r = FALSE;\r
1277         wchar_t* pw0 = NULL;\r
1278 START_ROUTINE\r
1279         pw0 = DuplicateMtoW(lpPathName, -1);\r
1280         r = SetCurrentDirectoryW(pw0);\r
1281 END_ROUTINE\r
1282         FreeDuplicatedString(pw0);\r
1283         return r;\r
1284 }\r
1285 \r
1286 DWORD GetTempPathM(DWORD nBufferLength, LPSTR lpBuffer)\r
1287 {\r
1288         DWORD r = 0;\r
1289         wchar_t* pw0 = NULL;\r
1290 START_ROUTINE\r
1291         pw0 = AllocateStringW(nBufferLength * 4);\r
1292         GetTempPathW(nBufferLength * 4, pw0);\r
1293         WtoM(lpBuffer, nBufferLength, pw0, -1);\r
1294         r = TerminateStringM(lpBuffer, nBufferLength);\r
1295 END_ROUTINE\r
1296         FreeDuplicatedString(pw0);\r
1297         return r;\r
1298 }\r
1299 \r
1300 DWORD GetFileAttributesM(LPCSTR lpFileName)\r
1301 {\r
1302         DWORD r = FALSE;\r
1303         wchar_t* pw0 = NULL;\r
1304 START_ROUTINE\r
1305         pw0 = DuplicateMtoW(lpFileName, -1);\r
1306         r = GetFileAttributesW(pw0);\r
1307 END_ROUTINE\r
1308         FreeDuplicatedString(pw0);\r
1309         return r;\r
1310 }\r
1311 \r
1312 DWORD GetModuleFileNameM(HMODULE hModule, LPCH lpFilename, DWORD nSize)\r
1313 {\r
1314         DWORD r = 0;\r
1315         wchar_t* pw0 = NULL;\r
1316 START_ROUTINE\r
1317         pw0 = AllocateStringW(nSize * 4);\r
1318         GetModuleFileNameW(hModule, pw0, nSize * 4);\r
1319         WtoM(lpFilename, nSize, pw0, -1);\r
1320         r = TerminateStringM(lpFilename, nSize);\r
1321 END_ROUTINE\r
1322         FreeDuplicatedString(pw0);\r
1323         return r;\r
1324 }\r
1325 \r
1326 LSTATUS RegOpenKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)\r
1327 {\r
1328         LSTATUS r = 0;\r
1329         wchar_t* pw0 = NULL;\r
1330 START_ROUTINE\r
1331         pw0 = DuplicateMtoW(lpSubKey, -1);\r
1332         r = RegOpenKeyExW(hKey, pw0, ulOptions, samDesired, phkResult);\r
1333 END_ROUTINE\r
1334         FreeDuplicatedString(pw0);\r
1335         return r;\r
1336 }\r
1337 \r
1338 LSTATUS RegCreateKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass, DWORD dwOptions, REGSAM samDesired, CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition)\r
1339 {\r
1340         LSTATUS r = 0;\r
1341         wchar_t* pw0 = NULL;\r
1342         wchar_t* pw1 = NULL;\r
1343 START_ROUTINE\r
1344         pw0 = DuplicateMtoW(lpSubKey, -1);\r
1345         pw1 = DuplicateMtoW(lpClass, -1);\r
1346         r = RegCreateKeyExW(hKey, pw0, Reserved, pw1, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition);\r
1347 END_ROUTINE\r
1348         FreeDuplicatedString(pw0);\r
1349         FreeDuplicatedString(pw1);\r
1350         return r;\r
1351 }\r
1352 \r
1353 LSTATUS RegDeleteValueM(HKEY hKey, LPCSTR lpValueName)\r
1354 {\r
1355         LSTATUS r = 0;\r
1356         wchar_t* pw0 = NULL;\r
1357 START_ROUTINE\r
1358         pw0 = DuplicateMtoW(lpValueName, -1);\r
1359         r = RegDeleteValueW(hKey, pw0);\r
1360 END_ROUTINE\r
1361         FreeDuplicatedString(pw0);\r
1362         return r;\r
1363 }\r
1364 \r
1365 LSTATUS RegQueryValueExM(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)\r
1366 {\r
1367         LSTATUS r = 0;\r
1368         wchar_t* pw0 = NULL;\r
1369         wchar_t* pw1 = NULL;\r
1370         DWORD dwType;\r
1371         DWORD wcbData;\r
1372 START_ROUTINE\r
1373         pw0 = DuplicateMtoW(lpValueName, -1);\r
1374         if(RegQueryValueExW(hKey, pw0, NULL, &dwType, NULL, 0) == ERROR_SUCCESS)\r
1375         {\r
1376                 switch(dwType)\r
1377                 {\r
1378                 case REG_SZ:\r
1379                 case REG_EXPAND_SZ:\r
1380                 case REG_MULTI_SZ:\r
1381                         if(lpcbData)\r
1382                         {\r
1383                                 pw1 = AllocateStringW(*lpcbData / sizeof(char) * 4);\r
1384                                 wcbData = *lpcbData / sizeof(char) * 4;\r
1385                                 r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, (LPBYTE)pw1, &wcbData);\r
1386                                 if(lpData)\r
1387                                         *lpcbData = sizeof(char) * WtoM((char*)lpData, *lpcbData / sizeof(char), pw1, wcbData / sizeof(wchar_t));\r
1388                                 else\r
1389                                         *lpcbData = sizeof(char) * WtoM(NULL, 0, pw1, wcbData / sizeof(wchar_t));\r
1390                         }\r
1391                         break;\r
1392                 default:\r
1393                         r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, lpData, lpcbData);\r
1394                         break;\r
1395                 }\r
1396         }\r
1397         else\r
1398                 r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, lpData, lpcbData);\r
1399 END_ROUTINE\r
1400         FreeDuplicatedString(pw0);\r
1401         FreeDuplicatedString(pw1);\r
1402         return r;\r
1403 }\r
1404 \r
1405 LSTATUS RegSetValueExM(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE* lpData, DWORD cbData)\r
1406 {\r
1407         LSTATUS r = 0;\r
1408         wchar_t* pw0 = NULL;\r
1409         wchar_t* pw1 = NULL;\r
1410         DWORD wcbData;\r
1411 START_ROUTINE\r
1412         pw0 = DuplicateMtoW(lpValueName, -1);\r
1413         switch(dwType)\r
1414         {\r
1415         case REG_SZ:\r
1416         case REG_EXPAND_SZ:\r
1417         case REG_MULTI_SZ:\r
1418                 wcbData = MtoW(NULL, 0, (char*)lpData, cbData / sizeof(char));\r
1419                 pw1 = AllocateStringW(wcbData);\r
1420                 MtoW(pw1, wcbData, (char*)lpData, cbData / sizeof(char));\r
1421                 wcbData = sizeof(wchar_t) * wcbData;\r
1422                 lpData = (BYTE*)pw1;\r
1423                 cbData = wcbData;\r
1424                 break;\r
1425         }\r
1426         r = RegSetValueExW(hKey, pw0, Reserved, dwType, lpData, cbData);\r
1427 END_ROUTINE\r
1428         FreeDuplicatedString(pw0);\r
1429         FreeDuplicatedString(pw1);\r
1430         return r;\r
1431 }\r
1432 \r
1433 BOOL TextOutM(HDC hdc, int x, int y, LPCSTR lpString, int c)\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 = TextOutW(hdc, x, y, pw0, wcslen(pw0));\r
1440 END_ROUTINE\r
1441         FreeDuplicatedString(pw0);\r
1442         return r;\r
1443 }\r
1444 \r
1445 BOOL GetTextExtentPoint32M(HDC hdc, LPCSTR lpString, int c, LPSIZE psizl)\r
1446 {\r
1447         BOOL r = FALSE;\r
1448         wchar_t* pw0 = NULL;\r
1449 START_ROUTINE\r
1450         pw0 = DuplicateMtoW(lpString, c);\r
1451         r = GetTextExtentPoint32W(hdc, pw0, wcslen(pw0), psizl);\r
1452 END_ROUTINE\r
1453         FreeDuplicatedString(pw0);\r
1454         return r;\r
1455 }\r
1456 \r
1457 INT_PTR PropertySheetM(LPCPROPSHEETHEADERA v0)\r
1458 {\r
1459         INT_PTR r = 0;\r
1460         PROPSHEETHEADERW a0;\r
1461         PROPSHEETPAGEW* pwPage;\r
1462         UINT i;\r
1463 START_ROUTINE\r
1464         a0.dwSize = sizeof(PROPSHEETHEADERW);\r
1465         a0.dwFlags = v0->dwFlags;\r
1466         a0.hwndParent = v0->hwndParent;\r
1467         a0.hInstance = v0->hInstance;\r
1468         if(v0->dwFlags & PSH_USEICONID)\r
1469                 a0.pszIcon = DuplicateMtoW(v0->pszIcon, -1);\r
1470         else\r
1471                 a0.hIcon = v0->hIcon;\r
1472         a0.pszCaption = DuplicateMtoW(v0->pszCaption, -1);\r
1473         a0.nPages = v0->nPages;\r
1474         if(v0->dwFlags & PSH_USEPSTARTPAGE)\r
1475                 a0.pStartPage = DuplicateMtoW(v0->pStartPage, -1);\r
1476         else\r
1477                 a0.nStartPage = v0->nStartPage;\r
1478         if(v0->dwFlags & PSH_PROPSHEETPAGE)\r
1479         {\r
1480                 if(v0->ppsp && (pwPage = (PROPSHEETPAGEW*)malloc(sizeof(PROPSHEETPAGEW) * v0->nPages)))\r
1481                 {\r
1482                         for(i = 0; i < v0->nPages; i++)\r
1483                         {\r
1484                                 pwPage[i].dwSize = sizeof(PROPSHEETPAGEW);\r
1485                                 pwPage[i].dwFlags = v0->ppsp[i].dwFlags;\r
1486                                 pwPage[i].hInstance = v0->ppsp[i].hInstance;\r
1487                                 if(v0->ppsp[i].dwFlags & PSP_DLGINDIRECT)\r
1488                                         pwPage[i].pResource = v0->ppsp[i].pResource;\r
1489                                 else\r
1490                                         pwPage[i].pszTemplate = DuplicateMtoW(v0->ppsp[i].pszTemplate, -1);\r
1491                                 if(v0->ppsp[i].dwFlags & PSP_USEICONID)\r
1492                                         pwPage[i].pszIcon = DuplicateMtoW(v0->ppsp[i].pszIcon, -1);\r
1493                                 else\r
1494                                         pwPage[i].hIcon = v0->ppsp[i].hIcon;\r
1495                                 if(v0->ppsp[i].dwFlags & PSP_USETITLE)\r
1496                                         pwPage[i].pszTitle = DuplicateMtoW(v0->ppsp[i].pszTitle, -1);\r
1497                                 pwPage[i].pfnDlgProc = v0->ppsp[i].pfnDlgProc;\r
1498                                 pwPage[i].lParam = v0->ppsp[i].lParam;\r
1499                                 // TODO: pfnCallback\r
1500                                 pwPage[i].pfnCallback = (LPFNPSPCALLBACKW)v0->ppsp[i].pfnCallback;\r
1501                                 pwPage[i].pcRefParent = v0->ppsp[i].pcRefParent;\r
1502                                 if(v0->ppsp[i].dwFlags & PSP_USEHEADERTITLE)\r
1503                                         pwPage[i].pszHeaderTitle = DuplicateMtoW(v0->ppsp[i].pszHeaderTitle, -1);\r
1504                                 if(v0->ppsp[i].dwFlags & PSP_USEHEADERSUBTITLE)\r
1505                                         pwPage[i].pszHeaderSubTitle = DuplicateMtoW(v0->ppsp[i].pszHeaderSubTitle, -1);\r
1506                         }\r
1507                 }\r
1508                 else\r
1509                         pwPage = NULL;\r
1510                 a0.ppsp = pwPage;\r
1511         }\r
1512         else\r
1513                 a0.phpage = v0->phpage;\r
1514         a0.pfnCallback = v0->pfnCallback;\r
1515         if(v0->dwFlags & PSH_USEHBMWATERMARK)\r
1516                 a0.hbmWatermark = v0->hbmWatermark;\r
1517         else\r
1518                 a0.pszbmWatermark = DuplicateMtoW(v0->pszbmWatermark, -1);\r
1519         r = PropertySheetW(&a0);\r
1520         if(a0.dwFlags & PSH_USEICONID)\r
1521                 FreeDuplicatedString((void*)a0.pszIcon);\r
1522         FreeDuplicatedString((void*)a0.pszCaption);\r
1523         if(v0->dwFlags & PSH_USEPSTARTPAGE)\r
1524                 FreeDuplicatedString((void*)a0.pStartPage);\r
1525         if(v0->dwFlags & PSH_PROPSHEETPAGE)\r
1526         {\r
1527                 if(pwPage)\r
1528                 {\r
1529                         for(i = 0; i < v0->nPages; i++)\r
1530                         {\r
1531                                 if(!(v0->ppsp[i].dwFlags & PSP_DLGINDIRECT))\r
1532                                         FreeDuplicatedString((void*)pwPage[i].pszTemplate);\r
1533                                 if(v0->ppsp[i].dwFlags & PSP_USEICONID)\r
1534                                         FreeDuplicatedString((void*)pwPage[i].pszIcon);\r
1535                                 if(v0->ppsp[i].dwFlags & PSP_USETITLE)\r
1536                                         FreeDuplicatedString((void*)pwPage[i].pszTitle);\r
1537                                 if(v0->ppsp[i].dwFlags & PSP_USEHEADERTITLE)\r
1538                                         FreeDuplicatedString((void*)pwPage[i].pszHeaderTitle);\r
1539                                 if(v0->ppsp[i].dwFlags & PSP_USEHEADERSUBTITLE)\r
1540                                         FreeDuplicatedString((void*)pwPage[i].pszHeaderSubTitle);\r
1541                         }\r
1542                         free(pwPage);\r
1543                 }\r
1544         }\r
1545         if(!(v0->dwFlags & PSH_USEHBMWATERMARK))\r
1546                 FreeDuplicatedString((void*)a0.pszbmWatermark);\r
1547 END_ROUTINE\r
1548         return r;\r
1549 }\r
1550 \r
1551 BOOL GetOpenFileNameM(LPOPENFILENAMEA v0)\r
1552 {\r
1553         BOOL r = FALSE;\r
1554         wchar_t* pw0 = NULL;\r
1555         wchar_t* pw1 = NULL;\r
1556         wchar_t* pw2 = NULL;\r
1557         wchar_t* pw3 = NULL;\r
1558         wchar_t* pw4 = NULL;\r
1559         wchar_t* pw5 = NULL;\r
1560         wchar_t* pw6 = NULL;\r
1561         wchar_t* pw7 = NULL;\r
1562         wchar_t* pw8 = NULL;\r
1563         wchar_t* pw9 = NULL;\r
1564         OPENFILENAMEW wofn;\r
1565 START_ROUTINE\r
1566         wofn.lStructSize = sizeof(OPENFILENAMEW);\r
1567         wofn.hwndOwner = v0->hwndOwner;\r
1568         wofn.hInstance = v0->hInstance;\r
1569         pw0 = DuplicateMtoWMultiString(v0->lpstrFilter);\r
1570         wofn.lpstrFilter = pw0;\r
1571         pw1 = DuplicateMtoWBuffer(v0->lpstrCustomFilter, -1, v0->nMaxCustFilter * 4);\r
1572         wofn.lpstrCustomFilter = pw1;\r
1573         wofn.nMaxCustFilter = v0->nMaxCustFilter * 4;\r
1574         wofn.nFilterIndex = v0->nFilterIndex;\r
1575         pw2 = DuplicateMtoWMultiStringBuffer(v0->lpstrFile, v0->nMaxFile * 4);\r
1576         wofn.lpstrFile = pw2;\r
1577         wofn.nMaxFile = v0->nMaxFile * 4;\r
1578         pw3 = DuplicateMtoWBuffer(v0->lpstrFileTitle, -1, v0->nMaxFileTitle * 4);\r
1579         wofn.lpstrFileTitle = pw3;\r
1580         wofn.nMaxFileTitle = v0->nMaxFileTitle * 4;\r
1581         pw4 = DuplicateMtoW(v0->lpstrInitialDir, -1);\r
1582         wofn.lpstrInitialDir = pw4;\r
1583         pw5 = DuplicateMtoW(v0->lpstrTitle, -1);\r
1584         wofn.lpstrTitle = pw5;\r
1585         wofn.Flags = v0->Flags;\r
1586         wofn.nFileOffset = MtoW(NULL, 0, v0->lpstrFile, v0->nFileOffset);\r
1587         wofn.nFileExtension = MtoW(NULL, 0, v0->lpstrFile, v0->nFileExtension);\r
1588         pw6 = DuplicateMtoW(v0->lpstrDefExt, -1);\r
1589         wofn.lpstrDefExt = pw6;\r
1590         wofn.lCustData = v0->lCustData;\r
1591         wofn.lpfnHook = v0->lpfnHook;\r
1592         wofn.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);\r
1593         wofn.pvReserved = v0->pvReserved;\r
1594         wofn.FlagsEx = v0->FlagsEx;\r
1595         r = GetOpenFileNameW(&wofn);\r
1596         WtoM(v0->lpstrFile, v0->nMaxFile, wofn.lpstrFile, -1);\r
1597         TerminateStringM(v0->lpstrFile, v0->nMaxFile);\r
1598         v0->nFileOffset = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileOffset);\r
1599         v0->nFileExtension = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileExtension);\r
1600 END_ROUTINE\r
1601         FreeDuplicatedString(pw0);\r
1602         FreeDuplicatedString(pw1);\r
1603         FreeDuplicatedString(pw2);\r
1604         FreeDuplicatedString(pw3);\r
1605         FreeDuplicatedString(pw4);\r
1606         FreeDuplicatedString(pw5);\r
1607         FreeDuplicatedString(pw6);\r
1608         return r;\r
1609 }\r
1610 \r
1611 BOOL GetSaveFileNameM(LPOPENFILENAMEA v0)\r
1612 {\r
1613         BOOL r = FALSE;\r
1614         wchar_t* pw0 = NULL;\r
1615         wchar_t* pw1 = NULL;\r
1616         wchar_t* pw2 = NULL;\r
1617         wchar_t* pw3 = NULL;\r
1618         wchar_t* pw4 = NULL;\r
1619         wchar_t* pw5 = NULL;\r
1620         wchar_t* pw6 = NULL;\r
1621         wchar_t* pw7 = NULL;\r
1622         wchar_t* pw8 = NULL;\r
1623         wchar_t* pw9 = NULL;\r
1624         OPENFILENAMEW wofn;\r
1625 START_ROUTINE\r
1626         wofn.lStructSize = sizeof(OPENFILENAMEW);\r
1627         wofn.hwndOwner = v0->hwndOwner;\r
1628         wofn.hInstance = v0->hInstance;\r
1629         pw0 = DuplicateMtoWMultiString(v0->lpstrFilter);\r
1630         wofn.lpstrFilter = pw0;\r
1631         pw1 = DuplicateMtoWBuffer(v0->lpstrCustomFilter, -1, v0->nMaxCustFilter * 4);\r
1632         wofn.lpstrCustomFilter = pw1;\r
1633         wofn.nMaxCustFilter = v0->nMaxCustFilter * 4;\r
1634         wofn.nFilterIndex = v0->nFilterIndex;\r
1635         pw2 = DuplicateMtoWMultiStringBuffer(v0->lpstrFile, v0->nMaxFile * 4);\r
1636         wofn.lpstrFile = pw2;\r
1637         wofn.nMaxFile = v0->nMaxFile * 4;\r
1638         pw3 = DuplicateMtoWBuffer(v0->lpstrFileTitle, -1, v0->nMaxFileTitle * 4);\r
1639         wofn.lpstrFileTitle = pw3;\r
1640         wofn.nMaxFileTitle = v0->nMaxFileTitle * 4;\r
1641         pw4 = DuplicateMtoW(v0->lpstrInitialDir, -1);\r
1642         wofn.lpstrInitialDir = pw4;\r
1643         pw5 = DuplicateMtoW(v0->lpstrTitle, -1);\r
1644         wofn.lpstrTitle = pw5;\r
1645         wofn.Flags = v0->Flags;\r
1646         wofn.nFileOffset = MtoW(NULL, 0, v0->lpstrFile, v0->nFileOffset);\r
1647         wofn.nFileExtension = MtoW(NULL, 0, v0->lpstrFile, v0->nFileExtension);\r
1648         pw6 = DuplicateMtoW(v0->lpstrDefExt, -1);\r
1649         wofn.lpstrDefExt = pw6;\r
1650         wofn.lCustData = v0->lCustData;\r
1651         wofn.lpfnHook = v0->lpfnHook;\r
1652         wofn.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);\r
1653         wofn.pvReserved = v0->pvReserved;\r
1654         wofn.FlagsEx = v0->FlagsEx;\r
1655         r = GetSaveFileNameW(&wofn);\r
1656         WtoM(v0->lpstrFile, v0->nMaxFile, wofn.lpstrFile, -1);\r
1657         TerminateStringM(v0->lpstrFile, v0->nMaxFile);\r
1658         v0->nFileOffset = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileOffset);\r
1659         v0->nFileExtension = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileExtension);\r
1660 END_ROUTINE\r
1661         FreeDuplicatedString(pw0);\r
1662         FreeDuplicatedString(pw1);\r
1663         FreeDuplicatedString(pw2);\r
1664         FreeDuplicatedString(pw3);\r
1665         FreeDuplicatedString(pw4);\r
1666         FreeDuplicatedString(pw5);\r
1667         FreeDuplicatedString(pw6);\r
1668         return r;\r
1669 }\r
1670 \r
1671 HWND HtmlHelpM(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData)\r
1672 {\r
1673         HWND r = NULL;\r
1674         wchar_t* pw0 = NULL;\r
1675 START_ROUTINE\r
1676         pw0 = DuplicateMtoW(pszFile, -1);\r
1677         r = HtmlHelpW(hwndCaller, pw0, uCommand, dwData);\r
1678 END_ROUTINE\r
1679         FreeDuplicatedString(pw0);\r
1680         return r;\r
1681 }\r
1682 \r
1683 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
1684 {\r
1685         BOOL r = FALSE;\r
1686         wchar_t* pw0 = NULL;\r
1687         wchar_t* pw1 = NULL;\r
1688         wchar_t* pw2 = NULL;\r
1689         wchar_t* pw3 = NULL;\r
1690         wchar_t* pw4 = NULL;\r
1691         wchar_t* pw5 = NULL;\r
1692         STARTUPINFOW wStartupInfo;\r
1693 START_ROUTINE\r
1694         pw0 = DuplicateMtoW(lpApplicationName, -1);\r
1695         pw1 = DuplicateMtoWBuffer(lpCommandLine, -1, (strlen(lpCommandLine) + 1) * 4);\r
1696         pw2 = DuplicateMtoW(lpCurrentDirectory, -1);\r
1697         wStartupInfo.cb = sizeof(LPSTARTUPINFOW);\r
1698         pw3 = DuplicateMtoW(lpStartupInfo->lpReserved, -1);\r
1699         wStartupInfo.lpReserved = pw3;\r
1700         pw4 = DuplicateMtoW(lpStartupInfo->lpDesktop, -1);\r
1701         wStartupInfo.lpDesktop = pw4;\r
1702         pw5 = DuplicateMtoW(lpStartupInfo->lpTitle, -1);\r
1703         wStartupInfo.lpTitle = pw5;\r
1704         wStartupInfo.dwX = lpStartupInfo->dwX;\r
1705         wStartupInfo.dwY = lpStartupInfo->dwY;\r
1706         wStartupInfo.dwXSize = lpStartupInfo->dwXSize;\r
1707         wStartupInfo.dwYSize = lpStartupInfo->dwYSize;\r
1708         wStartupInfo.dwXCountChars = lpStartupInfo->dwXCountChars;\r
1709         wStartupInfo.dwYCountChars = lpStartupInfo->dwYCountChars;\r
1710         wStartupInfo.dwFillAttribute = lpStartupInfo->dwFillAttribute;\r
1711         wStartupInfo.dwFlags = lpStartupInfo->dwFlags;\r
1712         wStartupInfo.wShowWindow = lpStartupInfo->wShowWindow;\r
1713         wStartupInfo.cbReserved2 = lpStartupInfo->cbReserved2;\r
1714         wStartupInfo.lpReserved2 = lpStartupInfo->lpReserved2;\r
1715         wStartupInfo.hStdInput = lpStartupInfo->hStdInput;\r
1716         wStartupInfo.hStdOutput = lpStartupInfo->hStdOutput;\r
1717         wStartupInfo.hStdError = lpStartupInfo->hStdError;\r
1718         r = CreateProcessW(pw0, pw1, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, pw2, &wStartupInfo, lpProcessInformation);\r
1719         WtoM(lpCommandLine, strlen(lpCommandLine) + 1, pw1, -1);\r
1720 END_ROUTINE\r
1721         FreeDuplicatedString(pw0);\r
1722         FreeDuplicatedString(pw1);\r
1723         FreeDuplicatedString(pw2);\r
1724         FreeDuplicatedString(pw3);\r
1725         FreeDuplicatedString(pw4);\r
1726         FreeDuplicatedString(pw5);\r
1727         return r;\r
1728 }\r
1729 \r
1730 HINSTANCE FindExecutableM(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)\r
1731 {\r
1732         HINSTANCE r = NULL;\r
1733         wchar_t* pw0 = NULL;\r
1734         wchar_t* pw1 = NULL;\r
1735         wchar_t* pw2 = NULL;\r
1736         wchar_t* pw3 = NULL;\r
1737 START_ROUTINE\r
1738         pw0 = DuplicateMtoW(lpFile, -1);\r
1739         pw1 = DuplicateMtoW(lpDirectory, -1);\r
1740         pw2 = AllocateStringW(MAX_PATH * 4);\r
1741         r = FindExecutableW(pw0, pw1, pw2);\r
1742         // バッファ長不明のためオーバーランの可能性あり\r
1743         WtoM(lpResult, MAX_PATH, pw2, -1);\r
1744         TerminateStringM(lpResult, MAX_PATH);\r
1745 END_ROUTINE\r
1746         FreeDuplicatedString(pw0);\r
1747         FreeDuplicatedString(pw1);\r
1748         FreeDuplicatedString(pw2);\r
1749         FreeDuplicatedString(pw3);\r
1750         return r;\r
1751 }\r
1752 \r
1753 HINSTANCE ShellExecuteM(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd)\r
1754 {\r
1755         HINSTANCE r = NULL;\r
1756         wchar_t* pw0 = NULL;\r
1757         wchar_t* pw1 = NULL;\r
1758         wchar_t* pw2 = NULL;\r
1759         wchar_t* pw3 = NULL;\r
1760 START_ROUTINE\r
1761         pw0 = DuplicateMtoW(lpOperation, -1);\r
1762         pw1 = DuplicateMtoW(lpFile, -1);\r
1763         pw2 = DuplicateMtoW(lpParameters, -1);\r
1764         pw3 = DuplicateMtoW(lpDirectory, -1);\r
1765         r = ShellExecuteW(hwnd, pw0, pw1, pw2, pw3, nShowCmd);\r
1766 END_ROUTINE\r
1767         FreeDuplicatedString(pw0);\r
1768         FreeDuplicatedString(pw1);\r
1769         FreeDuplicatedString(pw2);\r
1770         FreeDuplicatedString(pw3);\r
1771         return r;\r
1772 }\r
1773 \r
1774 BOOL ShellExecuteExM(LPSHELLEXECUTEINFOA lpExecInfo)\r
1775 {\r
1776         BOOL r = FALSE;\r
1777         wchar_t* pw0 = NULL;\r
1778         wchar_t* pw1 = NULL;\r
1779         wchar_t* pw2 = NULL;\r
1780         wchar_t* pw3 = NULL;\r
1781         wchar_t* pw4 = NULL;\r
1782         SHELLEXECUTEINFOW wExecInfo;\r
1783 START_ROUTINE\r
1784         wExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);\r
1785         wExecInfo.fMask = lpExecInfo->fMask;\r
1786         wExecInfo.hwnd = lpExecInfo->hwnd;\r
1787         pw0 = DuplicateMtoW(lpExecInfo->lpVerb, -1);\r
1788         wExecInfo.lpVerb = pw0;\r
1789         pw1 = DuplicateMtoW(lpExecInfo->lpFile, -1);\r
1790         wExecInfo.lpFile = pw1;\r
1791         pw2 = DuplicateMtoW(lpExecInfo->lpParameters, -1);\r
1792         wExecInfo.lpParameters = pw2;\r
1793         pw3 = DuplicateMtoW(lpExecInfo->lpDirectory, -1);\r
1794         wExecInfo.lpDirectory = pw3;\r
1795         wExecInfo.nShow = lpExecInfo->nShow;\r
1796         wExecInfo.hInstApp = lpExecInfo->hInstApp;\r
1797         wExecInfo.lpIDList = lpExecInfo->lpIDList;\r
1798         if(lpExecInfo->fMask & SEE_MASK_CLASSNAME)\r
1799         {\r
1800                 pw4 = DuplicateMtoW(lpExecInfo->lpClass, -1);\r
1801                 wExecInfo.lpClass = pw4;\r
1802         }\r
1803         wExecInfo.hkeyClass = lpExecInfo->hkeyClass;\r
1804         wExecInfo.dwHotKey = lpExecInfo->dwHotKey;\r
1805         wExecInfo.hIcon = lpExecInfo->hIcon;\r
1806         wExecInfo.hProcess = lpExecInfo->hProcess;\r
1807         r = ShellExecuteExW(&wExecInfo);\r
1808         lpExecInfo->hInstApp = wExecInfo.hInstApp;\r
1809         lpExecInfo->hProcess = wExecInfo.hProcess;\r
1810 END_ROUTINE\r
1811         FreeDuplicatedString(pw0);\r
1812         FreeDuplicatedString(pw1);\r
1813         FreeDuplicatedString(pw2);\r
1814         FreeDuplicatedString(pw3);\r
1815         FreeDuplicatedString(pw4);\r
1816         return r;\r
1817 }\r
1818 \r
1819 PIDLIST_ABSOLUTE SHBrowseForFolderM(LPBROWSEINFOA lpbi)\r
1820 {\r
1821         PIDLIST_ABSOLUTE r = NULL;\r
1822         wchar_t* pw0 = NULL;\r
1823         wchar_t* pw1 = NULL;\r
1824         BROWSEINFOW wbi;\r
1825 START_ROUTINE\r
1826         wbi.hwndOwner = lpbi->hwndOwner;\r
1827         wbi.pidlRoot = lpbi->pidlRoot;\r
1828         pw0 = DuplicateMtoWBuffer(lpbi->pszDisplayName, -1, MAX_PATH * 4);\r
1829         wbi.pszDisplayName = pw0;\r
1830         pw1 = DuplicateMtoW(lpbi->lpszTitle, -1);\r
1831         wbi.lpszTitle = pw1;\r
1832         wbi.ulFlags = lpbi->ulFlags;\r
1833         // TODO: lpfn\r
1834         wbi.lpfn = lpbi->lpfn;\r
1835         wbi.lParam = lpbi->lParam;\r
1836         wbi.iImage = lpbi->iImage;\r
1837         r = SHBrowseForFolderW(&wbi);\r
1838         // バッファ長不明のためオーバーランの可能性あり\r
1839         WtoM(lpbi->pszDisplayName, MAX_PATH, wbi.pszDisplayName, -1);\r
1840         lpbi->iImage = wbi.iImage;\r
1841 END_ROUTINE\r
1842         FreeDuplicatedString(pw0);\r
1843         FreeDuplicatedString(pw1);\r
1844         return r;\r
1845 }\r
1846 \r
1847 BOOL SHGetPathFromIDListM(PCIDLIST_ABSOLUTE pidl, LPSTR pszPath)\r
1848 {\r
1849         BOOL r = FALSE;\r
1850         wchar_t* pw0 = NULL;\r
1851 START_ROUTINE\r
1852         pw0 = AllocateStringW(MAX_PATH * 4);\r
1853         r = SHGetPathFromIDListW(pidl, pw0);\r
1854         // バッファ長不明のためオーバーランの可能性あり\r
1855         WtoM(pszPath, MAX_PATH, pw0, -1);\r
1856         TerminateStringM(pszPath, MAX_PATH);\r
1857 END_ROUTINE\r
1858         FreeDuplicatedString(pw0);\r
1859         return r;\r
1860 }\r
1861 \r
1862 int SHFileOperationM(LPSHFILEOPSTRUCTA lpFileOp)\r
1863 {\r
1864         int r = 0;\r
1865         wchar_t* pw0 = NULL;\r
1866         wchar_t* pw1 = NULL;\r
1867         wchar_t* pw2 = NULL;\r
1868         SHFILEOPSTRUCTW wFileOp;\r
1869 START_ROUTINE\r
1870         wFileOp.hwnd = lpFileOp->hwnd;\r
1871         wFileOp.wFunc = lpFileOp->wFunc;\r
1872         pw0 = DuplicateMtoWMultiString(lpFileOp->pFrom);\r
1873         wFileOp.pFrom = pw0;\r
1874         pw1 = DuplicateMtoWMultiString(lpFileOp->pTo);\r
1875         wFileOp.pTo = pw1;\r
1876         wFileOp.fFlags = lpFileOp->fFlags;\r
1877         wFileOp.fAnyOperationsAborted = lpFileOp->fAnyOperationsAborted;\r
1878         wFileOp.hNameMappings = lpFileOp->hNameMappings;\r
1879         if(lpFileOp->fFlags & FOF_SIMPLEPROGRESS)\r
1880                 pw2 = DuplicateMtoW(lpFileOp->lpszProgressTitle, -1);\r
1881         r = SHFileOperationW(&wFileOp);\r
1882         lpFileOp->fAnyOperationsAborted = wFileOp.fAnyOperationsAborted;\r
1883 END_ROUTINE\r
1884         FreeDuplicatedString(pw0);\r
1885         FreeDuplicatedString(pw1);\r
1886         FreeDuplicatedString(pw2);\r
1887         return r;\r
1888 }\r
1889 \r
1890 DWORD_PTR SHGetFileInfoM(LPCSTR pszPath, DWORD dwFileAttributes, SHFILEINFOA *psfi, UINT cbFileInfo, UINT uFlags)\r
1891 {\r
1892         DWORD_PTR r = 0;\r
1893         wchar_t* pw0 = NULL;\r
1894         SHFILEINFOW wsfi;\r
1895 START_ROUTINE\r
1896         pw0 = DuplicateMtoWMultiString(pszPath);\r
1897         if((r = SHGetFileInfoW(pw0, dwFileAttributes, &wsfi, cbFileInfo, uFlags)) != 0)\r
1898         {\r
1899                 psfi->hIcon = wsfi.hIcon;\r
1900                 psfi->iIcon = wsfi.iIcon;\r
1901                 psfi->dwAttributes = wsfi.dwAttributes;\r
1902                 WtoM(psfi->szDisplayName, MAX_PATH, wsfi.szDisplayName, -1);\r
1903                 WtoM(psfi->szTypeName, 80, wsfi.szTypeName, -1);\r
1904         }\r
1905 END_ROUTINE\r
1906         FreeDuplicatedString(pw0);\r
1907         return r;\r
1908 }\r
1909 \r
1910 BOOL AppendMenuM(HMENU hMenu, UINT uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem)\r
1911 {\r
1912         int r = 0;\r
1913         wchar_t* pw0 = NULL;\r
1914 START_ROUTINE\r
1915         if(uFlags & (MF_BITMAP | MF_OWNERDRAW))\r
1916                 r = AppendMenuW(hMenu, uFlags, uIDNewItem, (LPCWSTR)lpNewItem);\r
1917         else\r
1918         {\r
1919                 pw0 = DuplicateMtoW(lpNewItem, -1);\r
1920                 r = AppendMenuW(hMenu, uFlags, uIDNewItem, pw0);\r
1921         }\r
1922 END_ROUTINE\r
1923         FreeDuplicatedString(pw0);\r
1924         return r;\r
1925 }\r
1926 \r
1927 BOOL GetMenuItemInfoM(HMENU hmenu, UINT item, BOOL fByPosition, LPMENUITEMINFOA lpmii)\r
1928 {\r
1929         BOOL r = FALSE;\r
1930         wchar_t* pw0 = NULL;\r
1931         MENUITEMINFOW wmii;\r
1932 START_ROUTINE\r
1933         wmii.cbSize = sizeof(MENUITEMINFOW);\r
1934         wmii.fMask = lpmii->fMask;\r
1935         wmii.fType = lpmii->fType;\r
1936         wmii.fState = lpmii->fState;\r
1937         wmii.wID = lpmii->wID;\r
1938         wmii.hSubMenu = lpmii->hSubMenu;\r
1939         wmii.hbmpChecked = lpmii->hbmpChecked;\r
1940         wmii.hbmpUnchecked = lpmii->hbmpUnchecked;\r
1941         wmii.dwItemData = lpmii->dwItemData;\r
1942         if(lpmii->fMask & MIIM_TYPE)\r
1943         {\r
1944                 pw0 = DuplicateMtoWBuffer(lpmii->dwTypeData, -1, lpmii->cch * 4);\r
1945                 wmii.dwTypeData = pw0;\r
1946                 wmii.cch = lpmii->cch * 4;\r
1947         }\r
1948         wmii.hbmpItem = lpmii->hbmpItem;\r
1949         r = GetMenuItemInfoW(hmenu, item, fByPosition, &wmii);\r
1950         lpmii->fType = wmii.fType;\r
1951         lpmii->fState = wmii.fState;\r
1952         lpmii->wID = wmii.wID;\r
1953         lpmii->hSubMenu = wmii.hSubMenu;\r
1954         lpmii->hbmpChecked = wmii.hbmpChecked;\r
1955         lpmii->hbmpUnchecked = wmii.hbmpUnchecked;\r
1956         lpmii->dwItemData = wmii.dwItemData;\r
1957         WtoM(lpmii->dwTypeData, lpmii->cch, wmii.dwTypeData, -1);\r
1958         TerminateStringM(lpmii->dwTypeData, lpmii->cch);\r
1959 END_ROUTINE\r
1960         FreeDuplicatedString(pw0);\r
1961         return r;\r
1962 }\r
1963 \r
1964 HFONT CreateFontIndirectM(CONST LOGFONTA *lplf)\r
1965 {\r
1966         HFONT r = NULL;\r
1967         LOGFONTW wlf;\r
1968 START_ROUTINE\r
1969         wlf.lfHeight = lplf->lfHeight;\r
1970         wlf.lfWidth = lplf->lfWidth;\r
1971         wlf.lfEscapement = lplf->lfEscapement;\r
1972         wlf.lfOrientation = lplf->lfOrientation;\r
1973         wlf.lfWeight = lplf->lfWeight;\r
1974         wlf.lfItalic = lplf->lfItalic;\r
1975         wlf.lfUnderline = lplf->lfUnderline;\r
1976         wlf.lfStrikeOut = lplf->lfStrikeOut;\r
1977         wlf.lfCharSet = lplf->lfCharSet;\r
1978         wlf.lfOutPrecision = lplf->lfOutPrecision;\r
1979         wlf.lfClipPrecision = lplf->lfClipPrecision;\r
1980         wlf.lfQuality = lplf->lfQuality;\r
1981         wlf.lfPitchAndFamily = lplf->lfPitchAndFamily;\r
1982         MtoW(wlf.lfFaceName, LF_FACESIZE, lplf->lfFaceName, -1);\r
1983         TerminateStringW(wlf.lfFaceName, LF_FACESIZE);\r
1984         r = CreateFontIndirect(&wlf);\r
1985 END_ROUTINE\r
1986         return r;\r
1987 }\r
1988 \r
1989 BOOL ChooseFontM(LPCHOOSEFONTA v0)\r
1990 {\r
1991         BOOL r = FALSE;\r
1992         wchar_t* pw0 = NULL;\r
1993         wchar_t* pw1 = NULL;\r
1994         CHOOSEFONTW a0;\r
1995         LOGFONTW* pwlf;\r
1996 START_ROUTINE\r
1997         a0.lStructSize = sizeof(CHOOSEFONTW);\r
1998         a0.hwndOwner = v0->hwndOwner;\r
1999         a0.hDC = v0->hDC;\r
2000         if(v0->lpLogFont && (pwlf = (LOGFONTW*)malloc(sizeof(LOGFONTW))))\r
2001         {\r
2002                 pwlf->lfHeight = v0->lpLogFont->lfHeight;\r
2003                 pwlf->lfWidth = v0->lpLogFont->lfWidth;\r
2004                 pwlf->lfEscapement = v0->lpLogFont->lfEscapement;\r
2005                 pwlf->lfOrientation = v0->lpLogFont->lfOrientation;\r
2006                 pwlf->lfWeight = v0->lpLogFont->lfWeight;\r
2007                 pwlf->lfItalic = v0->lpLogFont->lfItalic;\r
2008                 pwlf->lfUnderline = v0->lpLogFont->lfUnderline;\r
2009                 pwlf->lfStrikeOut = v0->lpLogFont->lfStrikeOut;\r
2010                 pwlf->lfCharSet = v0->lpLogFont->lfCharSet;\r
2011                 pwlf->lfOutPrecision = v0->lpLogFont->lfOutPrecision;\r
2012                 pwlf->lfClipPrecision = v0->lpLogFont->lfClipPrecision;\r
2013                 pwlf->lfQuality = v0->lpLogFont->lfQuality;\r
2014                 pwlf->lfPitchAndFamily = v0->lpLogFont->lfPitchAndFamily;\r
2015                 MtoW(pwlf->lfFaceName, LF_FACESIZE, v0->lpLogFont->lfFaceName, -1);\r
2016                 TerminateStringW(pwlf->lfFaceName, LF_FACESIZE);\r
2017         }\r
2018         else\r
2019                 pwlf = NULL;\r
2020         a0.lpLogFont = pwlf;\r
2021         a0.iPointSize = v0->iPointSize;\r
2022         a0.Flags = v0->Flags;\r
2023         a0.rgbColors = v0->rgbColors;\r
2024         a0.lCustData = v0->lCustData;\r
2025         a0.lpfnHook = v0->lpfnHook;\r
2026         pw0 = DuplicateMtoW(v0->lpTemplateName, -1);\r
2027         a0.lpTemplateName = pw0;\r
2028         a0.hInstance = v0->hInstance;\r
2029         pw1 = DuplicateMtoWBuffer(v0->lpszStyle, -1, LF_FACESIZE * 4);\r
2030         a0.lpszStyle = pw1;\r
2031         a0.nFontType = v0->nFontType;\r
2032         a0.nSizeMin = v0->nSizeMin;\r
2033         a0.nSizeMax = v0->nSizeMax;\r
2034         r = ChooseFontW(&a0);\r
2035         if(v0->lpLogFont)\r
2036         {\r
2037                 v0->lpLogFont->lfHeight = pwlf->lfHeight;\r
2038                 v0->lpLogFont->lfWidth = pwlf->lfWidth;\r
2039                 v0->lpLogFont->lfEscapement = pwlf->lfEscapement;\r
2040                 v0->lpLogFont->lfOrientation = pwlf->lfOrientation;\r
2041                 v0->lpLogFont->lfWeight = pwlf->lfWeight;\r
2042                 v0->lpLogFont->lfItalic = pwlf->lfItalic;\r
2043                 v0->lpLogFont->lfUnderline = pwlf->lfUnderline;\r
2044                 v0->lpLogFont->lfStrikeOut = pwlf->lfStrikeOut;\r
2045                 v0->lpLogFont->lfCharSet = pwlf->lfCharSet;\r
2046                 v0->lpLogFont->lfOutPrecision = pwlf->lfOutPrecision;\r
2047                 v0->lpLogFont->lfClipPrecision = pwlf->lfClipPrecision;\r
2048                 v0->lpLogFont->lfQuality = pwlf->lfQuality;\r
2049                 v0->lpLogFont->lfPitchAndFamily = pwlf->lfPitchAndFamily;\r
2050                 WtoM(v0->lpLogFont->lfFaceName, LF_FACESIZE, pwlf->lfFaceName, -1);\r
2051                 TerminateStringM(v0->lpLogFont->lfFaceName, LF_FACESIZE);\r
2052         }\r
2053         v0->rgbColors = a0.rgbColors;\r
2054         WtoM(v0->lpszStyle, LF_FACESIZE, pw1, -1);\r
2055         TerminateStringM(v0->lpszStyle, LF_FACESIZE);\r
2056         v0->nFontType = a0.nFontType;\r
2057         if(pwlf)\r
2058                 free(pwlf);\r
2059 END_ROUTINE\r
2060         FreeDuplicatedString(pw0);\r
2061         FreeDuplicatedString(pw1);\r
2062         return r;\r
2063 }\r
2064 \r
2065 INT_PTR DialogBoxParamM(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)\r
2066 {\r
2067         INT_PTR r = 0;\r
2068         wchar_t* pw0 = NULL;\r
2069 START_ROUTINE\r
2070         pw0 = DuplicateMtoW(lpTemplateName, -1);\r
2071         r = DialogBoxParamW(hInstance, pw0, hWndParent, lpDialogFunc, dwInitParam);\r
2072 END_ROUTINE\r
2073         FreeDuplicatedString(pw0);\r
2074         return r;\r
2075 }\r
2076 \r
2077 HWND CreateDialogParamM(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)\r
2078 {\r
2079         HWND r = NULL;\r
2080         wchar_t* pw0 = NULL;\r
2081 START_ROUTINE\r
2082         pw0 = DuplicateMtoW(lpTemplateName, -1);\r
2083         r = CreateDialogParamW(hInstance, pw0, hWndParent, lpDialogFunc, dwInitParam);\r
2084 END_ROUTINE\r
2085         FreeDuplicatedString(pw0);\r
2086         return r;\r
2087 }\r
2088 \r
2089 BOOL sndPlaySoundM(LPCSTR pszSound, UINT fuSound)\r
2090 {\r
2091         BOOL r = FALSE;\r
2092         wchar_t* pw0 = NULL;\r
2093 START_ROUTINE\r
2094         pw0 = DuplicateMtoW(pszSound, -1);\r
2095         r = sndPlaySoundW(pw0, fuSound);\r
2096 END_ROUTINE\r
2097         FreeDuplicatedString(pw0);\r
2098         return r;\r
2099 }\r
2100 \r
2101 HANDLE SetClipboardDataM(UINT uFormat, HANDLE hMem)\r
2102 {\r
2103         HANDLE r = NULL;\r
2104         char* p;\r
2105         int Length;\r
2106         int BufferLength;\r
2107         HGLOBAL hBufferMem;\r
2108 START_ROUTINE\r
2109         if(uFormat == CF_TEXT)\r
2110         {\r
2111                 p = (char*)GlobalLock(hMem);\r
2112                 Length = (int)GlobalSize(hMem);\r
2113                 BufferLength = MtoW(NULL, 0, p, Length);\r
2114                 if(hBufferMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * BufferLength))\r
2115                 {\r
2116                         MtoW((LPWSTR)GlobalLock(hBufferMem), BufferLength, p, Length);\r
2117                         GlobalUnlock(hBufferMem);\r
2118                         r = SetClipboardData(CF_UNICODETEXT, hBufferMem);\r
2119                 }\r
2120                 GlobalUnlock(hMem);\r
2121                 GlobalFree(hMem);\r
2122         }\r
2123         else\r
2124                 r = SetClipboardData(uFormat, hMem);\r
2125 END_ROUTINE\r
2126         return r;\r
2127 }\r
2128 \r
2129 BOOL CopyFileM(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExists)\r
2130 {\r
2131         BOOL r = FALSE;\r
2132         wchar_t* pw0 = NULL;\r
2133         wchar_t* pw1 = NULL;\r
2134 START_ROUTINE\r
2135         pw0 = DuplicateMtoW(lpExistingFileName, -1);\r
2136         pw1 = DuplicateMtoW(lpNewFileName, -1);\r
2137         r = CopyFileW(pw0, pw1, bFailIfExists);\r
2138 END_ROUTINE\r
2139         FreeDuplicatedString(pw0);\r
2140         FreeDuplicatedString(pw1);\r
2141         return r;\r
2142 }\r
2143 \r
2144 BOOL MoveFileM(LPCSTR lpExistingFileName, LPCSTR lpNewFileName)\r
2145 {\r
2146         BOOL r = FALSE;\r
2147         wchar_t* pw0 = NULL;\r
2148         wchar_t* pw1 = NULL;\r
2149 START_ROUTINE\r
2150         pw0 = DuplicateMtoW(lpExistingFileName, -1);\r
2151         pw1 = DuplicateMtoW(lpNewFileName, -1);\r
2152         r = MoveFileW(pw0, pw1);\r
2153 END_ROUTINE\r
2154         FreeDuplicatedString(pw0);\r
2155         FreeDuplicatedString(pw1);\r
2156         return r;\r
2157 }\r
2158 \r
2159 int mkdirM(const char * _Path)\r
2160 {\r
2161         int r = -1;\r
2162         wchar_t* pw0 = NULL;\r
2163 START_ROUTINE\r
2164         pw0 = DuplicateMtoW(_Path, -1);\r
2165         r = _wmkdir(pw0);\r
2166 END_ROUTINE\r
2167         FreeDuplicatedString(pw0);\r
2168         return r;\r
2169 }\r
2170 \r
2171 int _mkdirM(const char * _Path)\r
2172 {\r
2173         int r = -1;\r
2174         wchar_t* pw0 = NULL;\r
2175 START_ROUTINE\r
2176         pw0 = DuplicateMtoW(_Path, -1);\r
2177         r = _wmkdir(pw0);\r
2178 END_ROUTINE\r
2179         FreeDuplicatedString(pw0);\r
2180         return r;\r
2181 }\r
2182 \r
2183 int rmdirM(const char * _Path)\r
2184 {\r
2185         int r = -1;\r
2186         wchar_t* pw0 = NULL;\r
2187 START_ROUTINE\r
2188         pw0 = DuplicateMtoW(_Path, -1);\r
2189         r = _wrmdir(pw0);\r
2190 END_ROUTINE\r
2191         FreeDuplicatedString(pw0);\r
2192         return r;\r
2193 }\r
2194 \r
2195 int _rmdirM(const char * _Path)\r
2196 {\r
2197         int r = -1;\r
2198         wchar_t* pw0 = NULL;\r
2199 START_ROUTINE\r
2200         pw0 = DuplicateMtoW(_Path, -1);\r
2201         r = _wrmdir(pw0);\r
2202 END_ROUTINE\r
2203         FreeDuplicatedString(pw0);\r
2204         return r;\r
2205 }\r
2206 \r
2207 int removeM(const char * _Filename)\r
2208 {\r
2209         int r = -1;\r
2210         wchar_t* pw0 = NULL;\r
2211 START_ROUTINE\r
2212         pw0 = DuplicateMtoW(_Filename, -1);\r
2213         r = _wremove(pw0);\r
2214 END_ROUTINE\r
2215         FreeDuplicatedString(pw0);\r
2216         return r;\r
2217 }\r
2218 \r
2219 int _removeM(const char * _Filename)\r
2220 {\r
2221         int r = -1;\r
2222         wchar_t* pw0 = NULL;\r
2223 START_ROUTINE\r
2224         pw0 = DuplicateMtoW(_Filename, -1);\r
2225         r = _wremove(pw0);\r
2226 END_ROUTINE\r
2227         FreeDuplicatedString(pw0);\r
2228         return r;\r
2229 }\r
2230 \r
2231 int _unlinkM(const char * _Filename)\r
2232 {\r
2233         int r = -1;\r
2234         wchar_t* pw0 = NULL;\r
2235 START_ROUTINE\r
2236         pw0 = DuplicateMtoW(_Filename, -1);\r
2237         r = _wunlink(pw0);\r
2238 END_ROUTINE\r
2239         FreeDuplicatedString(pw0);\r
2240         return r;\r
2241 }\r
2242 \r
2243 size_t _mbslenM(const unsigned char * _Str)\r
2244 {\r
2245         size_t r = 0;\r
2246 START_ROUTINE\r
2247         while(GetNextCharM(_Str, &_Str) > 0)\r
2248         {\r
2249                 r++;\r
2250         }\r
2251 END_ROUTINE\r
2252         return r;\r
2253 }\r
2254 \r
2255 unsigned char * _mbschrM(const unsigned char * _Str, unsigned int _Ch)\r
2256 {\r
2257         unsigned char* r = NULL;\r
2258         unsigned int c;\r
2259         unsigned char* p;\r
2260 START_ROUTINE\r
2261         while((c = GetNextCharM(_Str, &p)) > 0)\r
2262         {\r
2263                 if(c == _Ch)\r
2264                         break;\r
2265                 _Str = p;\r
2266         }\r
2267         if(c == _Ch)\r
2268                 r = (unsigned char*)_Str;\r
2269 END_ROUTINE\r
2270         return r;\r
2271 }\r
2272 \r
2273 unsigned char * _mbsrchrM(const unsigned char * _Str, unsigned int _Ch)\r
2274 {\r
2275         unsigned char* r = NULL;\r
2276         unsigned int c;\r
2277         unsigned char* p;\r
2278 START_ROUTINE\r
2279         while((c = GetNextCharM(_Str, &p)) > 0)\r
2280         {\r
2281                 if(c == _Ch)\r
2282                         r = (unsigned char*)_Str;\r
2283                 _Str = p;\r
2284         }\r
2285         if(c == _Ch)\r
2286                 r = (unsigned char*)_Str;\r
2287 END_ROUTINE\r
2288         return r;\r
2289 }\r
2290 \r
2291 unsigned char * _mbsstrM(const unsigned char * _Str, const unsigned char * _Substr)\r
2292 {\r
2293         unsigned char* r = NULL;\r
2294 START_ROUTINE\r
2295         r = strstr(_Str, _Substr);\r
2296 END_ROUTINE\r
2297         return r;\r
2298 }\r
2299 \r
2300 int _mbscmpM(const unsigned char * _Str1, const unsigned char * _Str2)\r
2301 {\r
2302         int r = 0;\r
2303 START_ROUTINE\r
2304         r = strcmp(_Str1, _Str2);\r
2305 END_ROUTINE\r
2306         return r;\r
2307 }\r
2308 \r
2309 int _mbsicmpM(const unsigned char * _Str1, const unsigned char * _Str2)\r
2310 {\r
2311         int r = 0;\r
2312 START_ROUTINE\r
2313         r = _stricmp(_Str1, _Str2);\r
2314 END_ROUTINE\r
2315         return r;\r
2316 }\r
2317 \r
2318 int _mbsncmpM(const unsigned char * _Str1, const unsigned char * _Str2, size_t _MaxCount)\r
2319 {\r
2320         int r = 0;\r
2321         DWORD c1;\r
2322         DWORD c2;\r
2323 START_ROUTINE\r
2324         c1 = 0;\r
2325         c2 = 0;\r
2326         while(_MaxCount > 0)\r
2327         {\r
2328                 c1 = GetNextCharM(_Str1, &_Str1);\r
2329                 c2 = GetNextCharM(_Str2, &_Str2);\r
2330                 if(c1 != c2)\r
2331                         break;\r
2332                 _MaxCount--;\r
2333                 if(c1 == 0 || c2 == 0)\r
2334                         break;\r
2335         }\r
2336         r = c1 - c2;\r
2337 END_ROUTINE\r
2338         return r;\r
2339 }\r
2340 \r
2341 unsigned char * _mbslwrM(unsigned char * _String)\r
2342 {\r
2343         unsigned char* r = NULL;\r
2344 START_ROUTINE\r
2345         r = _strlwr(_String);\r
2346 END_ROUTINE\r
2347         return r;\r
2348 }\r
2349 \r
2350 unsigned char * _mbsuprM(unsigned char * _String)\r
2351 {\r
2352         unsigned char* r = NULL;\r
2353 START_ROUTINE\r
2354         r = _strupr(_String);\r
2355 END_ROUTINE\r
2356         return r;\r
2357 }\r
2358 \r
2359 unsigned char * _mbsnincM(const unsigned char * _Str, size_t _Count)\r
2360 {\r
2361         unsigned char* r = NULL;\r
2362 START_ROUTINE\r
2363         while(_Count > 0 && GetNextCharM(_Str, &_Str) > 0)\r
2364         {\r
2365                 _Count--;\r
2366         }\r
2367         r = (unsigned char*)_Str;\r
2368 END_ROUTINE\r
2369         return r;\r
2370 }\r
2371 \r
2372 FILE * fopenM(const char * _Filename, const char * _Mode)\r
2373 {\r
2374         FILE* r = NULL;\r
2375         wchar_t* pw0 = NULL;\r
2376         wchar_t* pw1 = NULL;\r
2377 START_ROUTINE\r
2378         pw0 = DuplicateMtoW(_Filename, -1);\r
2379         pw1 = DuplicateMtoW(_Mode, -1);\r
2380         r = _wfopen(pw0, pw1);\r
2381 END_ROUTINE\r
2382         FreeDuplicatedString(pw0);\r
2383         FreeDuplicatedString(pw1);\r
2384         return r;\r
2385 }\r
2386 \r