OSDN Git Service

Add UTF-8 to UTF-16 API bridge.
[ffftp/ffftp.git] / mbswrapper.c
1 // mbswrapper.cpp
2 // Copyright (C) 2011 Suguru Kawamoto
3 // \83}\83\8b\83`\83o\83C\83g\95\8e\9a\83\8f\83C\83h\95\8e\9aAPI\83\89\83b\83p\81[
4 // \83}\83\8b\83`\83o\83C\83g\95\8e\9a\82ÍUTF-8\81A\83\8f\83C\83h\95\8e\9a\82ÍUTF-16\82Å\82 \82é\82à\82Ì\82Æ\82·\82é
5 // \91S\82Ä\82Ì\90§\8cä\97p\82Ì\95\8e\9a\82ÍASCII\82Ì\94Í\88Í\82Å\82 \82é\82½\82ß\81AShift_JIS\82ÆUTF-8\8aÔ\82Ì\95Ï\8a·\82Í\95s\97v
6
7 #define UNICODE
8 #define _WIN32_WINNT 0x0600
9 #undef _WIN32_IE
10 #define _WIN32_IE 0x0400
11
12 #include <tchar.h>
13 #include <windows.h>
14 #include <commctrl.h>
15 #include <shlobj.h>
16 #include <htmlhelp.h>
17
18 #define DO_NOT_REPLACE
19 #include "mbswrapper.h"
20
21 // \83}\83\8b\83`\83o\83C\83g\95\8e\9a\97ñ\82©\82ç\83\8f\83C\83h\95\8e\9a\97ñ\82Ö\95Ï\8a·
22 int MtoW(LPWSTR pDst, int size, LPCSTR pSrc, int count)
23 {
24         if(pSrc < (LPCSTR)0x00010000 || !((char*)pSrc + 1))
25                 return 0;
26         if(pDst)
27                 return MultiByteToWideChar(CP_UTF8, 0, pSrc, count, pDst, size);
28         return MultiByteToWideChar(CP_UTF8, 0, pSrc, count, NULL, 0);
29 }
30
31 // \83\8f\83C\83h\95\8e\9a\97ñ\82©\82ç\83}\83\8b\83`\83o\83C\83g\95\8e\9a\97ñ\82Ö\95Ï\8a·
32 int WtoM(LPSTR pDst, int size, LPCWSTR pSrc, int count)
33 {
34         if(pSrc < (LPCWSTR)0x00010000 || !((char*)pSrc + 1))
35                 return 0;
36         if(pDst)
37                 return WideCharToMultiByte(CP_UTF8, 0, pSrc, count, pDst, size, NULL, NULL);
38         return WideCharToMultiByte(CP_UTF8, 0, pSrc, count, NULL, 0, NULL, NULL);
39 }
40
41 // \83\8f\83C\83h\95\8e\9a\97ñ\82©\82çShift_JIS\95\8e\9a\97ñ\82Ö\95Ï\8a·
42 int WtoA(LPSTR pDst, int size, LPCWSTR pSrc, int count)
43 {
44         if(pSrc < (LPCWSTR)0x00010000 || !((char*)pSrc + 1))
45                 return 0;
46         if(pDst)
47                 return WideCharToMultiByte(CP_ACP, 0, pSrc, count, pDst, size, NULL, NULL);
48         return WideCharToMultiByte(CP_ACP, 0, pSrc, count, NULL, 0, NULL, NULL);
49 }
50
51 // \83}\83\8b\83`\83o\83C\83g\95\8e\9a\97ñ\83o\83b\83t\83@\8fI\92[\82ð\8b­\90§\93I\82ÉNULL\82Å\92u\8a·
52 int TerminateStringM(LPSTR lpString, int size)
53 {
54         int i;
55         if(lpString < (LPSTR)0x00010000 || !((char*)lpString + 1))
56                 return 0;
57         for(i = 0; i < size; i++)
58         {
59                 if(lpString[i] == '\0')
60                         return i;
61         }
62         i--;
63         lpString[i] = '\0';
64         return i;
65 }
66
67 // \83\8f\83C\83h\95\8e\9a\97ñ\83o\83b\83t\83@\8fI\92[\82ð\8b­\90§\93I\82ÉNULL\82Å\92u\8a·
68 int TerminateStringW(LPWSTR lpString, int size)
69 {
70         int i;
71         if(lpString < (LPWSTR)0x00010000 || !((char*)lpString + 1))
72                 return 0;
73         for(i = 0; i < size; i++)
74         {
75                 if(lpString[i] == L'\0')
76                         return i;
77         }
78         i--;
79         lpString[i] = L'\0';
80         return i;
81 }
82
83 // NULL\8bæ\90Ø\82è\95¡\90\94\83}\83\8b\83`\83o\83C\83g\95\8e\9a\97ñ\82Ì\92·\82³\82ð\8eæ\93¾
84 size_t GetMultiStringLengthM(LPCSTR lpString)
85 {
86         size_t i;
87         if(lpString < (LPCSTR)0x00010000 || !((char*)lpString + 1))
88                 return 0;
89         i = 0;
90         while(lpString[i] != '\0' || lpString[i + 1] != '\0')
91         {
92                 i++;
93         }
94         i++;
95         return i;
96 }
97
98 // NULL\8bæ\90Ø\82è\95¡\90\94\83\8f\83C\83h\95\8e\9a\97ñ\82Ì\92·\82³\82ð\8eæ\93¾
99 size_t GetMultiStringLengthW(LPCWSTR lpString)
100 {
101         size_t i;
102         if(lpString < (LPCWSTR)0x00010000 || !((char*)lpString + 1))
103                 return 0;
104         i = 0;
105         while(lpString[i] != L'\0' || lpString[i + 1] != L'\0')
106         {
107                 i++;
108         }
109         i++;
110         return i;
111 }
112
113 // \83}\83\8b\83`\83o\83C\83g\95\8e\9a\97ñ\97p\82Ì\83\81\83\82\83\8a\82ð\8am\95Û
114 char* AllocateStringM(int size)
115 {
116         char* p;
117         p = (char*)malloc(sizeof(char) * size);
118         if(p)
119                 *p = '\0';
120         return p;
121 }
122
123 // \83\8f\83C\83h\95\8e\9a\97ñ\97p\82Ì\83\81\83\82\83\8a\82ð\8am\95Û
124 wchar_t* AllocateStringW(int size)
125 {
126         wchar_t* p;
127         p = (wchar_t*)malloc(sizeof(wchar_t) * size);
128         if(p)
129                 *p = L'\0';
130         return p;
131 }
132
133 // Shift_JIS\95\8e\9a\97ñ\97p\82Ì\83\81\83\82\83\8a\82ð\8am\95Û
134 char* AllocateStringA(int size)
135 {
136         char* p;
137         p = (char*)malloc(sizeof(char) * size);
138         if(p)
139                 *p = '\0';
140         return p;
141 }
142
143 // \83\81\83\82\83\8a\82ð\8am\95Û\82µ\82Ä\83}\83\8b\83`\83o\83C\83g\95\8e\9a\97ñ\82©\82ç\83\8f\83C\83h\95\8e\9a\97ñ\82Ö\95Ï\8a·
144 wchar_t* DuplicateMtoW(LPCSTR lpString, int c)
145 {
146         wchar_t* p;
147         int i;
148         if(lpString < (LPCSTR)0x00010000 || !((char*)lpString + 1))
149                 return (wchar_t*)lpString;
150         if(c < 0)
151                 c = strlen(lpString);
152         p = AllocateStringW(MtoW(NULL, 0, lpString, c) + 1);
153         if(p)
154         {
155                 i = MtoW(p, 65535, lpString, c);
156                 p[i] = L'\0';
157         }
158         return p;
159 }
160
161 // \8ew\92è\82µ\82½\83T\83C\83Y\82Ì\83\81\83\82\83\8a\82ð\8am\95Û\82µ\82Ä\83}\83\8b\83`\83o\83C\83g\95\8e\9a\97ñ\82©\82ç\83\8f\83C\83h\95\8e\9a\97ñ\82Ö\95Ï\8a·
162 wchar_t* DuplicateMtoWBuffer(LPCSTR lpString, int c, int size)
163 {
164         wchar_t* p;
165         int i;
166         if(lpString < (LPCSTR)0x00010000 || !((char*)lpString + 1))
167                 return (wchar_t*)lpString;
168         if(c < 0)
169                 c = strlen(lpString);
170         p = AllocateStringW(size);
171         if(p)
172         {
173                 i = MtoW(p, size, lpString, c);
174                 p[i] = L'\0';
175         }
176         return p;
177 }
178
179 // \83\81\83\82\83\8a\82ð\8am\95Û\82µ\82ÄNULL\8bæ\90Ø\82è\83}\83\8b\83`\83o\83C\83g\95\8e\9a\97ñ\82©\82ç\83\8f\83C\83h\95\8e\9a\97ñ\82Ö\95Ï\8a·
180 wchar_t* DuplicateMtoWMultiString(LPCSTR lpString)
181 {
182         int count;
183         wchar_t* p;
184         if(lpString < (LPCSTR)0x00010000 || !((char*)lpString + 1))
185                 return (wchar_t*)lpString;
186         count = GetMultiStringLengthM(lpString) + 1;
187         p = AllocateStringW(count);
188         if(p)
189                 MtoW(p, count, lpString, count);
190         return p;
191 }
192
193 // \8ew\92è\82µ\82½\83T\83C\83Y\82Ì\83\81\83\82\83\8a\82ð\8am\95Û\82µ\82ÄNULL\8bæ\90Ø\82è\83}\83\8b\83`\83o\83C\83g\95\8e\9a\97ñ\82©\82ç\83\8f\83C\83h\95\8e\9a\97ñ\82Ö\95Ï\8a·
194 wchar_t* DuplicateMtoWMultiStringBuffer(LPCSTR lpString, int size)
195 {
196         int count;
197         wchar_t* p;
198         if(lpString < (LPCSTR)0x00010000 || !((char*)lpString + 1))
199                 return (wchar_t*)lpString;
200         count = GetMultiStringLengthM(lpString) + 1;
201         p = AllocateStringW(size);
202         if(p)
203         {
204                 MtoW(p, size, lpString, count);
205                 p[size - 2] = L'\0';
206                 p[size - 1] = L'\0';
207         }
208         return p;
209 }
210
211 // \83\81\83\82\83\8a\82ð\8am\95Û\82µ\82Ä\83\8f\83C\83h\95\8e\9a\97ñ\82©\82ç\83}\83\8b\83`\83o\83C\83g\95\8e\9a\97ñ\82Ö\95Ï\8a·
212 char* DuplicateWtoM(LPCWSTR lpString, int c)
213 {
214         char* p;
215         int i;
216         if(lpString < (LPCWSTR)0x00010000 || !((char*)lpString + 1))
217                 return (char*)lpString;
218         if(c < 0)
219                 c = wcslen(lpString);
220         p = AllocateStringM(WtoM(NULL, 0, lpString, c) + 1);
221         if(p)
222         {
223                 i = WtoM(p, 65535, lpString, c);
224                 p[i] = L'\0';
225         }
226         return p;
227 }
228
229 // \83\81\83\82\83\8a\82ð\8am\95Û\82µ\82Ä\83\8f\83C\83h\95\8e\9a\97ñ\82©\82çShift_JIS\95\8e\9a\97ñ\82Ö\95Ï\8a·
230 char* DuplicateWtoA(LPCWSTR lpString, int c)
231 {
232         char* p;
233         int i;
234         if(lpString < (LPCWSTR)0x00010000 || !((char*)lpString + 1))
235                 return (char*)lpString;
236         if(c < 0)
237                 c = wcslen(lpString);
238         p = AllocateStringA(WtoA(NULL, 0, lpString, c) + 1);
239         if(p)
240         {
241                 i = WtoA(p, 65535, lpString, c);
242                 p[i] = L'\0';
243         }
244         return p;
245 }
246
247 // \95\8e\9a\97ñ\97p\82É\8am\95Û\82µ\82½\83\81\83\82\83\8a\82ð\8aJ\95ú
248 void FreeDuplicatedString(void* p)
249 {
250         if(p < (void*)0x00010000 || !((char*)p + 1))
251                 return;
252         free(p);
253 }
254
255 // \88È\89º\83\89\83b\83p\81[
256 // \96ß\82è\92l\83o\83b\83t\83@ r
257 // \83\8f\83C\83h\95\8e\9a\83o\83b\83t\83@ pw%d
258 // \83}\83\8b\83`\83o\83C\83g\95\8e\9a\83o\83b\83t\83@ pm%d
259 // \88ø\90\94\83o\83b\83t\83@ a%d
260
261 #define START_ROUTINE                                   do{
262 #define END_ROUTINE                                             }while(0);end_of_routine:
263 #define QUIT_ROUTINE                                    goto end_of_routine;
264
265 HANDLE CreateFileM(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
266 {
267         HANDLE r = INVALID_HANDLE_VALUE;
268         wchar_t* pw0 = NULL;
269 START_ROUTINE
270         pw0 = DuplicateMtoW(lpFileName, -1);
271         r = CreateFileW(pw0, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
272 END_ROUTINE
273         FreeDuplicatedString(pw0);
274         return r;
275 }
276
277 int MessageBoxM(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
278 {
279         int r = IDOK;
280         wchar_t* pw0 = NULL;
281         wchar_t* pw1 = NULL;
282 START_ROUTINE
283         pw0 = DuplicateMtoW(lpText, -1);
284         pw1 = DuplicateMtoW(lpCaption, -1);
285         r = MessageBoxW(hWnd, pw0, pw1, uType);
286 END_ROUTINE
287         FreeDuplicatedString(pw0);
288         FreeDuplicatedString(pw1);
289         return r;
290 }
291
292 HANDLE FindFirstFileM(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
293 {
294         HANDLE r = INVALID_HANDLE_VALUE;
295         wchar_t* pw0 = NULL;
296         WIN32_FIND_DATAW a0;
297 START_ROUTINE
298         pw0 = DuplicateMtoW(lpFileName, -1);
299         r = FindFirstFileW(pw0, &a0);
300         if(r != INVALID_HANDLE_VALUE)
301         {
302                 lpFindFileData->dwFileAttributes = a0.dwFileAttributes;
303                 lpFindFileData->ftCreationTime = a0.ftCreationTime;
304                 lpFindFileData->ftLastAccessTime = a0.ftLastAccessTime;
305                 lpFindFileData->ftLastWriteTime = a0.ftLastWriteTime;
306                 lpFindFileData->nFileSizeHigh = a0.nFileSizeHigh;
307                 lpFindFileData->nFileSizeLow = a0.nFileSizeLow;
308                 lpFindFileData->dwReserved0 = a0.dwReserved0;
309                 lpFindFileData->dwReserved1 = a0.dwReserved1;
310                 WtoM(lpFindFileData->cFileName, sizeof(lpFindFileData->cFileName), a0.cFileName, -1);
311                 WtoM(lpFindFileData->cAlternateFileName, sizeof(lpFindFileData->cAlternateFileName), a0.cAlternateFileName, -1);
312         }
313 END_ROUTINE
314         FreeDuplicatedString(pw0);
315         return r;
316 }
317
318 BOOL FindNextFileM(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData)
319 {
320         BOOL r = FALSE;
321         WIN32_FIND_DATAW a0;
322 START_ROUTINE
323         r = FindNextFileW(hFindFile, &a0);
324         if(r)
325         {
326                 lpFindFileData->dwFileAttributes = a0.dwFileAttributes;
327                 lpFindFileData->ftCreationTime = a0.ftCreationTime;
328                 lpFindFileData->ftLastAccessTime = a0.ftLastAccessTime;
329                 lpFindFileData->ftLastWriteTime = a0.ftLastWriteTime;
330                 lpFindFileData->nFileSizeHigh = a0.nFileSizeHigh;
331                 lpFindFileData->nFileSizeLow = a0.nFileSizeLow;
332                 lpFindFileData->dwReserved0 = a0.dwReserved0;
333                 lpFindFileData->dwReserved1 = a0.dwReserved1;
334                 WtoM(lpFindFileData->cFileName, sizeof(lpFindFileData->cFileName), a0.cFileName, -1);
335                 WtoM(lpFindFileData->cAlternateFileName, sizeof(lpFindFileData->cAlternateFileName), a0.cAlternateFileName, -1);
336         }
337 END_ROUTINE
338         return r;
339 }
340
341 DWORD GetLogicalDriveStringsM(DWORD nBufferLength, LPSTR lpBuffer)
342 {
343         // TODO: \96{\97\88\82Í\95Ï\8a·\82ª\95K\97v\82¾\82ª\94¼\8ap\89p\90\94\82Ì\82Ý\82Æ\8ev\82í\82ê\82é\82Ì\82Å\8fÈ\97ª
344         return GetLogicalDriveStringsA(nBufferLength, lpBuffer);
345 }
346
347 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)
348 {
349         HWND r = NULL;
350         wchar_t* pw0 = NULL;
351         wchar_t* pw1 = NULL;
352 START_ROUTINE
353         pw0 = DuplicateMtoW(lpClassName, -1);
354         pw1 = DuplicateMtoW(lpWindowName, -1);
355         r = CreateWindowExW(dwExStyle, pw0, pw1, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
356 END_ROUTINE
357         FreeDuplicatedString(pw0);
358         FreeDuplicatedString(pw1);
359         return r;
360 }
361
362 LRESULT SendMessageM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
363 {
364         LRESULT r = 0;
365         wchar_t* pw0 = NULL;
366         wchar_t* pw1 = NULL;
367         int Size;
368         LVITEMA* pmLVItem;
369         LVITEMW wLVItem;
370         LVFINDINFOA* pmLVFindInfo;
371         LVFINDINFOW wLVFindInfo;
372         LVCOLUMNA* pmLVColumn;
373         LVCOLUMNW wLVColumn;
374         wchar_t ClassName[MAX_PATH];
375 START_ROUTINE
376         switch(Msg)
377         {
378         case WM_SETTEXT:
379                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
380                 r = SendMessageW(hWnd, WM_SETTEXT, wParam, (LPARAM)pw0);
381                 break;
382         case WM_GETTEXT:
383                 pw0 = AllocateStringW(wParam * 4);
384                 SendMessageW(hWnd, WM_GETTEXT, wParam * 4, (LPARAM)pw0);
385                 WtoM((LPSTR)lParam, wParam, pw0, -1);
386                 r = TerminateStringM((LPSTR)lParam, wParam);
387                 break;
388         case WM_GETTEXTLENGTH:
389                 Size = SendMessageW(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1;
390                 pw0 = AllocateStringW(Size);
391                 SendMessageW(hWnd, WM_GETTEXT, (WPARAM)Size, (LPARAM)pw0);
392                 r = WtoM(NULL, 0, pw0, -1) - 1;
393                 break;
394         default:
395                 GetClassNameW(hWnd, ClassName, sizeof(ClassName) / sizeof(wchar_t));
396                 if(wcsicmp(ClassName, WC_EDITW) == 0)
397                 {
398                         switch(Msg)
399                         {
400                         case EM_REPLACESEL:
401                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
402                                 r = SendMessageW(hWnd, EM_REPLACESEL, wParam, (LPARAM)pw0);
403                                 break;
404                         default:
405                                 r = SendMessageW(hWnd, Msg, wParam, lParam);
406                                 break;
407                         }
408                 }
409                 else if(wcsicmp(ClassName, WC_COMBOBOXW) == 0)
410                 {
411                         switch(Msg)
412                         {
413                         case CB_ADDSTRING:
414                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
415                                 r = SendMessageW(hWnd, CB_ADDSTRING, wParam, (LPARAM)pw0);
416                                 break;
417                         case CB_INSERTSTRING:
418                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
419                                 r = SendMessageW(hWnd, CB_INSERTSTRING, wParam, (LPARAM)pw0);
420                                 break;
421                         case CB_FINDSTRINGEXACT:
422                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
423                                 r = SendMessageW(hWnd, CB_FINDSTRINGEXACT, wParam, (LPARAM)pw0);
424                                 break;
425                         default:
426                                 r = SendMessageW(hWnd, Msg, wParam, lParam);
427                                 break;
428                         }
429                 }
430                 else if(wcsicmp(ClassName, WC_LISTBOXW) == 0)
431                 {
432                         switch(Msg)
433                         {
434                         case LB_ADDSTRING:
435                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
436                                 r = SendMessageW(hWnd, LB_ADDSTRING, wParam, (LPARAM)pw0);
437                                 break;
438                         case LB_INSERTSTRING:
439                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
440                                 r = SendMessageW(hWnd, LB_INSERTSTRING, wParam, (LPARAM)pw0);
441                                 break;
442                         case LB_GETTEXT:
443                                 Size = SendMessageW(hWnd, LB_GETTEXTLEN, wParam, 0) + 1;
444                                 pw0 = AllocateStringW(Size * 4);
445                                 SendMessageW(hWnd, LB_GETTEXT, wParam, (LPARAM)pw0);
446                                 // \83o\83b\83t\83@\92·\95s\96¾\82Ì\82½\82ß\83I\81[\83o\81[\83\89\83\93\82Ì\89Â\94\\90«\82 \82è
447                                 WtoM((LPSTR)lParam, Size * 4, pw0, -1);
448                                 r = TerminateStringM((LPSTR)lParam, Size * 4);
449                                 break;
450                         default:
451                                 r = SendMessageW(hWnd, Msg, wParam, lParam);
452                                 break;
453                         }
454                 }
455                 else if(wcsicmp(ClassName, WC_LISTVIEWW) == 0)
456                 {
457                         switch(Msg)
458                         {
459                         case LVM_GETITEMA:
460                                 pmLVItem = (LVITEMA*)lParam;
461                                 wLVItem.mask = pmLVItem->mask;
462                                 wLVItem.iItem = pmLVItem->iItem;
463                                 wLVItem.iSubItem = pmLVItem->iSubItem;
464                                 wLVItem.state = pmLVItem->state;
465                                 wLVItem.stateMask = pmLVItem->stateMask;
466                                 Size = pmLVItem->cchTextMax * 4;
467                                 pw0 = AllocateStringW(Size);
468                                 wLVItem.pszText = pw0;
469                                 wLVItem.cchTextMax = Size;
470                                 wLVItem.iImage = pmLVItem->iImage;
471                                 wLVItem.lParam = pmLVItem->lParam;
472                                 wLVItem.iIndent = pmLVItem->iIndent;
473                                 r = SendMessageW(hWnd, LVM_GETITEMW, wParam, (LPARAM)&wLVItem);
474                                 pmLVItem->mask = wLVItem.mask;
475                                 pmLVItem->iItem = wLVItem.iItem;
476                                 pmLVItem->iSubItem = wLVItem.iSubItem;
477                                 pmLVItem->state = wLVItem.state;
478                                 pmLVItem->stateMask = wLVItem.stateMask;
479                                 WtoM(pmLVItem->pszText, pmLVItem->cchTextMax, wLVItem.pszText, -1);
480                                 TerminateStringM(pmLVItem->pszText, pmLVItem->cchTextMax);
481                                 pmLVItem->iImage = wLVItem.iImage;
482                                 pmLVItem->lParam = wLVItem.lParam;
483                                 pmLVItem->iIndent = wLVItem.iIndent;
484                                 break;
485                         case LVM_SETITEMA:
486                                 pmLVItem = (LVITEMA*)lParam;
487                                 wLVItem.mask = pmLVItem->mask;
488                                 wLVItem.iItem = pmLVItem->iItem;
489                                 wLVItem.iSubItem = pmLVItem->iSubItem;
490                                 wLVItem.state = pmLVItem->state;
491                                 wLVItem.stateMask = pmLVItem->stateMask;
492                                 pw0 = DuplicateMtoW(pmLVItem->pszText, -1);
493                                 wLVItem.pszText = pw0;
494                                 // TODO: cchTextMax\82Ì\8am\94F
495                                 wLVItem.cchTextMax = pmLVItem->cchTextMax;
496                                 wLVItem.iImage = pmLVItem->iImage;
497                                 wLVItem.lParam = pmLVItem->lParam;
498                                 wLVItem.iIndent = pmLVItem->iIndent;
499                                 r = SendMessageW(hWnd, LVM_SETITEMW, wParam, (LPARAM)&wLVItem);
500                                 break;
501                         case LVM_INSERTITEMA:
502                                 pmLVItem = (LVITEMA*)lParam;
503                                 wLVItem.mask = pmLVItem->mask;
504                                 wLVItem.iItem = pmLVItem->iItem;
505                                 wLVItem.iSubItem = pmLVItem->iSubItem;
506                                 wLVItem.state = pmLVItem->state;
507                                 wLVItem.stateMask = pmLVItem->stateMask;
508                                 pw0 = DuplicateMtoW(pmLVItem->pszText, -1);
509                                 wLVItem.pszText = pw0;
510                                 // TODO: cchTextMax\82Ì\8am\94F
511                                 wLVItem.cchTextMax = pmLVItem->cchTextMax;
512                                 wLVItem.iImage = pmLVItem->iImage;
513                                 wLVItem.lParam = pmLVItem->lParam;
514                                 wLVItem.iIndent = pmLVItem->iIndent;
515                                 r = SendMessageW(hWnd, LVM_INSERTITEMW, wParam, (LPARAM)&wLVItem);
516                                 break;
517                         case LVM_FINDITEMA:
518                                 pmLVFindInfo = (LVFINDINFOA*)lParam;
519                                 wLVFindInfo.flags = pmLVFindInfo->flags;
520                                 pw0 = DuplicateMtoW(pmLVFindInfo->psz, -1);
521                                 wLVFindInfo.psz = pw0;
522                                 wLVFindInfo.lParam = pmLVFindInfo->lParam;
523                                 wLVFindInfo.pt = pmLVFindInfo->pt;
524                                 wLVFindInfo.vkDirection = pmLVFindInfo->vkDirection;
525                                 r = SendMessageW(hWnd, LVM_FINDITEMW, wParam, (LPARAM)&wLVItem);
526                                 break;
527                         case LVM_INSERTCOLUMNA:
528                                 pmLVColumn = (LVCOLUMNA*)lParam;
529                                 wLVColumn.mask = pmLVColumn->mask;
530                                 wLVColumn.fmt = pmLVColumn->fmt;
531                                 wLVColumn.cx = pmLVColumn->cx;
532                                 pw0 = DuplicateMtoW(pmLVColumn->pszText, -1);
533                                 wLVColumn.pszText = pw0;
534                                 wLVColumn.cchTextMax = pmLVColumn->cchTextMax;
535                                 wLVColumn.iSubItem = pmLVColumn->iSubItem;
536                                 wLVColumn.iImage = pmLVColumn->iImage;
537                                 wLVColumn.iOrder = pmLVColumn->iOrder;
538                                 r = SendMessageW(hWnd, LVM_INSERTCOLUMNW, wParam, (LPARAM)&wLVColumn);
539                                 break;
540                         case LVM_GETITEMTEXTA:
541                                 pmLVItem = (LVITEMA*)lParam;
542                                 wLVItem.mask = pmLVItem->mask;
543                                 wLVItem.iItem = pmLVItem->iItem;
544                                 wLVItem.iSubItem = pmLVItem->iSubItem;
545                                 wLVItem.state = pmLVItem->state;
546                                 wLVItem.stateMask = pmLVItem->stateMask;
547                                 Size = pmLVItem->cchTextMax * 4;
548                                 pw0 = AllocateStringW(Size);
549                                 wLVItem.pszText = pw0;
550                                 wLVItem.cchTextMax = Size;
551                                 wLVItem.iImage = pmLVItem->iImage;
552                                 wLVItem.lParam = pmLVItem->lParam;
553                                 wLVItem.iIndent = pmLVItem->iIndent;
554                                 r = SendMessageW(hWnd, LVM_GETITEMTEXTW, wParam, (LPARAM)&wLVItem);
555                                 pmLVItem->mask = wLVItem.mask;
556                                 pmLVItem->iItem = wLVItem.iItem;
557                                 pmLVItem->iSubItem = wLVItem.iSubItem;
558                                 pmLVItem->state = wLVItem.state;
559                                 pmLVItem->stateMask = wLVItem.stateMask;
560                                 WtoM(pmLVItem->pszText, pmLVItem->cchTextMax, wLVItem.pszText, -1);
561                                 TerminateStringM(pmLVItem->pszText, pmLVItem->cchTextMax);
562                                 pmLVItem->iImage = wLVItem.iImage;
563                                 pmLVItem->lParam = wLVItem.lParam;
564                                 pmLVItem->iIndent = wLVItem.iIndent;
565                                 break;
566                         default:
567                                 r = SendMessageW(hWnd, Msg, wParam, lParam);
568                                 break;
569                         }
570                 }
571                 else if(wcsicmp(ClassName, STATUSCLASSNAMEW) == 0)
572                 {
573                         switch(Msg)
574                         {
575                         case SB_SETTEXTA:
576                                 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
577                                 r = SendMessageW(hWnd, SB_SETTEXTW, wParam, (LPARAM)pw0);
578                                 break;
579                         default:
580                                 r = SendMessageW(hWnd, Msg, wParam, lParam);
581                                 break;
582                         }
583                 }
584                 else
585                         r = SendMessageW(hWnd, Msg, wParam, lParam);
586                 break;
587         }
588 END_ROUTINE
589         FreeDuplicatedString(pw0);
590         FreeDuplicatedString(pw1);
591         return r;
592 }
593
594 LRESULT SendDlgItemMessageM(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam)
595 {
596         LRESULT r = 0;
597 START_ROUTINE
598         r = SendMessageM(GetDlgItem(hDlg, nIDDlgItem), Msg, wParam, lParam);
599 END_ROUTINE
600         return r;
601 }
602
603 BOOL SetWindowTextM(HWND hWnd, LPCSTR lpString)
604 {
605         BOOL r = FALSE;
606         wchar_t* pw0 = NULL;
607 START_ROUTINE
608         pw0 = DuplicateMtoW(lpString, -1);
609         r = SetWindowTextW(hWnd, pw0);
610 END_ROUTINE
611         FreeDuplicatedString(pw0);
612         return r;
613 }
614
615 UINT DragQueryFileM(HDROP hDrop, UINT iFile, LPSTR lpszFile, UINT cch)
616 {
617         UINT r = 0;
618         wchar_t* pw0 = NULL;
619 START_ROUTINE
620         pw0 = AllocateStringW(cch * 4);
621         DragQueryFileW(hDrop, iFile, pw0, cch * 4);
622         WtoM(lpszFile, cch, pw0, -1);
623         r = TerminateStringM(lpszFile, cch);
624 END_ROUTINE
625         FreeDuplicatedString(pw0);
626         return r;
627 }
628
629 DWORD GetCurrentDirectoryM(DWORD nBufferLength, LPSTR lpBuffer)
630 {
631         DWORD r = 0;
632         wchar_t* pw0 = NULL;
633 START_ROUTINE
634         pw0 = AllocateStringW(nBufferLength * 4);
635         GetCurrentDirectoryW(nBufferLength * 4, pw0);
636         WtoM(lpBuffer, nBufferLength, pw0, -1);
637         r = TerminateStringM(lpBuffer, nBufferLength);
638 END_ROUTINE
639         FreeDuplicatedString(pw0);
640         return r;
641 }
642
643 BOOL SetCurrentDirectoryM(LPCSTR lpPathName)
644 {
645         BOOL r = FALSE;
646         wchar_t* pw0 = NULL;
647 START_ROUTINE
648         pw0 = DuplicateMtoW(lpPathName, -1);
649         r = SetCurrentDirectoryW(pw0);
650 END_ROUTINE
651         FreeDuplicatedString(pw0);
652         return r;
653 }
654
655 BOOL SetDllDirectoryM(LPCSTR lpPathName)
656 {
657         BOOL r = FALSE;
658         wchar_t* pw0 = NULL;
659 START_ROUTINE
660         pw0 = DuplicateMtoW(lpPathName, -1);
661         r = SetDllDirectoryW(pw0);
662 END_ROUTINE
663         FreeDuplicatedString(pw0);
664         return r;
665 }
666
667 DWORD GetFileAttributesM(LPCSTR lpFileName)
668 {
669         DWORD r = FALSE;
670         wchar_t* pw0 = NULL;
671 START_ROUTINE
672         pw0 = DuplicateMtoW(lpFileName, -1);
673         r = GetFileAttributesW(pw0);
674 END_ROUTINE
675         FreeDuplicatedString(pw0);
676         return r;
677 }
678
679 DWORD GetModuleFileNameM(HMODULE hModule, LPCH lpFilename, DWORD nSize)
680 {
681         DWORD r = 0;
682         wchar_t* pw0 = NULL;
683 START_ROUTINE
684         pw0 = AllocateStringW(nSize * 4);
685         GetModuleFileNameW(hModule, pw0, nSize * 4);
686         WtoM(lpFilename, nSize, pw0, -1);
687         r = TerminateStringM(lpFilename, nSize);
688 END_ROUTINE
689         FreeDuplicatedString(pw0);
690         return r;
691 }
692
693 LSTATUS RegOpenKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
694 {
695         LSTATUS r = 0;
696         wchar_t* pw0 = NULL;
697 START_ROUTINE
698         pw0 = DuplicateMtoW(lpSubKey, -1);
699         r = RegOpenKeyExW(hKey, pw0, ulOptions, samDesired, phkResult);
700 END_ROUTINE
701         FreeDuplicatedString(pw0);
702         return r;
703 }
704
705 LSTATUS RegCreateKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass, DWORD dwOptions, REGSAM samDesired, CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition)
706 {
707         LSTATUS r = 0;
708         wchar_t* pw0 = NULL;
709         wchar_t* pw1 = NULL;
710 START_ROUTINE
711         pw0 = DuplicateMtoW(lpSubKey, -1);
712         pw1 = DuplicateMtoW(lpClass, -1);
713         r = RegCreateKeyExW(hKey, pw0, Reserved, pw1, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition);
714 END_ROUTINE
715         FreeDuplicatedString(pw0);
716         FreeDuplicatedString(pw1);
717         return r;
718 }
719
720 LSTATUS RegDeleteValueM(HKEY hKey, LPCSTR lpValueName)
721 {
722         LSTATUS r = 0;
723         wchar_t* pw0 = NULL;
724 START_ROUTINE
725         pw0 = DuplicateMtoW(lpValueName, -1);
726         r = RegDeleteValueW(hKey, pw0);
727 END_ROUTINE
728         FreeDuplicatedString(pw0);
729         return r;
730 }
731
732 LSTATUS RegQueryValueExM(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)
733 {
734         LSTATUS r = 0;
735         wchar_t* pw0 = NULL;
736 START_ROUTINE
737         pw0 = DuplicateMtoW(lpValueName, -1);
738         // TODO: \83\8c\83W\83X\83g\83\8a\82ÍUTF-8\82Å\95Û\91\82³\82ê\82Ä\82µ\82Ü\82¤\81i\88È\91O\82Ì\83o\81[\83W\83\87\83\93\82Æ\8cÝ\8a·\90«\82È\82µ\81j
739         // UTF-16\82Å\95Û\91\82·\82é\82×\82«
740         r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, lpData, lpcbData);
741 END_ROUTINE
742         FreeDuplicatedString(pw0);
743         return r;
744 }
745
746 LSTATUS RegSetValueExM(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE* lpData, DWORD cbData)
747 {
748         LSTATUS r = 0;
749         wchar_t* pw0 = NULL;
750 START_ROUTINE
751         pw0 = DuplicateMtoW(lpValueName, -1);
752         // TODO: \83\8c\83W\83X\83g\83\8a\82ÍUTF-8\82Å\95Û\91\82³\82ê\82Ä\82µ\82Ü\82¤\81i\88È\91O\82Ì\83o\81[\83W\83\87\83\93\82Æ\8cÝ\8a·\90«\82È\82µ\81j
753         // UTF-16\82Å\95Û\91\82·\82é\82×\82«
754         r = RegSetValueExW(hKey, pw0, Reserved, dwType, lpData, cbData);
755 END_ROUTINE
756         FreeDuplicatedString(pw0);
757         return r;
758 }
759
760 BOOL TextOutM(HDC hdc, int x, int y, LPCSTR lpString, int c)
761 {
762         BOOL r = FALSE;
763         wchar_t* pw0 = NULL;
764 START_ROUTINE
765         pw0 = DuplicateMtoW(lpString, c);
766         r = TextOutW(hdc, x, y, pw0, wcslen(pw0));
767 END_ROUTINE
768         FreeDuplicatedString(pw0);
769         return r;
770 }
771
772 BOOL GetTextExtentPoint32M(HDC hdc, LPCSTR lpString, int c, LPSIZE psizl)
773 {
774         BOOL r = FALSE;
775         wchar_t* pw0 = NULL;
776 START_ROUTINE
777         pw0 = DuplicateMtoW(lpString, c);
778         r = GetTextExtentPoint32W(hdc, pw0, wcslen(pw0), psizl);
779 END_ROUTINE
780         FreeDuplicatedString(pw0);
781         return r;
782 }
783
784 INT_PTR PropertySheetM(LPCPROPSHEETHEADERA v0)
785 {
786         INT_PTR r = 0;
787         PROPSHEETHEADERW a0;
788         PROPSHEETPAGEW* pwPage;
789         UINT i;
790 START_ROUTINE
791         a0.dwSize = sizeof(PROPSHEETHEADERW);
792         a0.dwFlags = v0->dwFlags;
793         a0.hwndParent = v0->hwndParent;
794         a0.hInstance = v0->hInstance;
795         if(v0->dwFlags & PSH_USEICONID)
796                 a0.pszIcon = DuplicateMtoW(v0->pszIcon, -1);
797         else
798                 a0.hIcon = v0->hIcon;
799         a0.pszCaption = DuplicateMtoW(v0->pszCaption, -1);
800         a0.nPages = v0->nPages;
801         a0.pStartPage = DuplicateMtoW(v0->pStartPage, -1);
802         if(v0->ppsp && (pwPage = (PROPSHEETPAGEW*)malloc(sizeof(PROPSHEETPAGEW) * v0->nPages)))
803         {
804                 for(i = 0; i < v0->nPages; i++)
805                 {
806                         pwPage[i].dwSize = sizeof(PROPSHEETPAGEW);
807                         pwPage[i].dwFlags = v0->ppsp[i].dwFlags;
808                         pwPage[i].hInstance = v0->ppsp[i].hInstance;
809                         pwPage[i].pszTemplate = DuplicateMtoW(v0->ppsp[i].pszTemplate, -1);
810                         if(v0->ppsp[i].dwFlags & PSP_USEICONID)
811                                 pwPage[i].pszIcon = DuplicateMtoW(v0->ppsp[i].pszIcon, -1);
812                         else
813                                 pwPage[i].hIcon = v0->ppsp[i].hIcon;
814                         if(v0->ppsp[i].dwFlags & PSP_USETITLE)
815                                 pwPage[i].pszTitle = DuplicateMtoW(v0->ppsp[i].pszTitle, -1);
816                         pwPage[i].pfnDlgProc = v0->ppsp[i].pfnDlgProc;
817                         pwPage[i].lParam = v0->ppsp[i].lParam;
818                         // TODO: pfnCallback
819                         pwPage[i].pfnCallback = v0->ppsp[i].pfnCallback;
820                         pwPage[i].pcRefParent = v0->ppsp[i].pcRefParent;
821 //                      pwPage[i].pszHeaderTitle = DuplicateMtoW(v0->ppsp[i].pszHeaderTitle, -1);
822 //                      pwPage[i].pszHeaderSubTitle = DuplicateMtoW(v0->ppsp[i].pszHeaderSubTitle, -1);
823                         pwPage[i].hActCtx = v0->ppsp[i].hActCtx;
824 //                      pwPage[i].pszbmHeader = DuplicateMtoW(v0->ppsp[i].pszbmHeader, -1);
825                 }
826         }
827         else
828                 pwPage = NULL;
829         a0.ppsp = pwPage;
830         a0.pfnCallback = v0->pfnCallback;
831         r = PropertySheetW(&a0);
832         if(a0.dwFlags & PSH_USEICONID)
833                 FreeDuplicatedString(a0.pszIcon);
834         FreeDuplicatedString(a0.pszCaption);
835         FreeDuplicatedString(a0.pStartPage);
836         if(pwPage)
837         {
838                 for(i = 0; i < v0->nPages; i++)
839                 {
840                         FreeDuplicatedString(pwPage[i].pszTemplate);
841                         if(pwPage[i].dwFlags & PSP_USEICONID)
842                                 FreeDuplicatedString(pwPage[i].pszIcon);
843                         if(pwPage[i].dwFlags & PSP_USETITLE)
844                                 FreeDuplicatedString(pwPage[i].pszTitle);
845 //                      FreeDuplicatedString(pwPage[i].pszHeaderTitle);
846 //                      FreeDuplicatedString(pwPage[i].pszHeaderSubTitle);
847 //                      FreeDuplicatedString(pwPage[i].pszbmHeader);
848                 }
849                 free(pwPage);
850         }
851 END_ROUTINE
852         return r;
853 }
854
855 BOOL GetOpenFileNameM(LPOPENFILENAMEA v0)
856 {
857         BOOL r = FALSE;
858         wchar_t* pw0 = NULL;
859         wchar_t* pw1 = NULL;
860         wchar_t* pw2 = NULL;
861         wchar_t* pw3 = NULL;
862         wchar_t* pw4 = NULL;
863         wchar_t* pw5 = NULL;
864         wchar_t* pw6 = NULL;
865         wchar_t* pw7 = NULL;
866         wchar_t* pw8 = NULL;
867         wchar_t* pw9 = NULL;
868         OPENFILENAMEW wofn;
869 START_ROUTINE
870         wofn.lStructSize = sizeof(OPENFILENAMEW);
871         wofn.hwndOwner = v0->hwndOwner;
872         wofn.hInstance = v0->hInstance;
873         pw0 = DuplicateMtoWMultiString(v0->lpstrFilter);
874         wofn.lpstrFilter = pw0;
875         pw1 = DuplicateMtoWBuffer(v0->lpstrCustomFilter, -1, v0->nMaxCustFilter * 4);
876         wofn.lpstrCustomFilter = pw1;
877         wofn.nMaxCustFilter = v0->nMaxCustFilter * 4;
878         wofn.nFilterIndex = v0->nFilterIndex;
879         pw2 = DuplicateMtoWMultiStringBuffer(v0->lpstrFile, v0->nMaxFile * 4);
880         wofn.lpstrFile = pw2;
881         wofn.nMaxFile = v0->nMaxFile * 4;
882         pw3 = DuplicateMtoWBuffer(v0->lpstrFileTitle, -1, v0->nMaxFileTitle * 4);
883         wofn.lpstrFileTitle = pw3;
884         wofn.nMaxFileTitle = v0->nMaxFileTitle * 4;
885         pw4 = DuplicateMtoW(v0->lpstrInitialDir, -1);
886         wofn.lpstrInitialDir = pw4;
887         pw5 = DuplicateMtoW(v0->lpstrTitle, -1);
888         wofn.lpstrTitle = pw5;
889         wofn.Flags = v0->Flags;
890         wofn.nFileOffset = MtoW(NULL, 0, v0->lpstrFile, v0->nFileOffset);
891         wofn.nFileExtension = MtoW(NULL, 0, v0->lpstrFile, v0->nFileExtension);
892         pw6 = DuplicateMtoW(v0->lpstrDefExt, -1);
893         wofn.lpstrDefExt = pw6;
894         wofn.lCustData = v0->lCustData;
895         wofn.lpfnHook = v0->lpfnHook;
896         wofn.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);
897         wofn.pvReserved = v0->pvReserved;
898         wofn.FlagsEx = v0->FlagsEx;
899         r = GetOpenFileNameW(&wofn);
900         WtoM(v0->lpstrFile, v0->nMaxFile, wofn.lpstrFile, -1);
901         TerminateStringM(v0->lpstrFile, v0->nMaxFile);
902         v0->nFileOffset = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileOffset);
903         v0->nFileExtension = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileExtension);
904 END_ROUTINE
905         FreeDuplicatedString(pw0);
906         FreeDuplicatedString(pw1);
907         FreeDuplicatedString(pw2);
908         FreeDuplicatedString(pw3);
909         FreeDuplicatedString(pw4);
910         FreeDuplicatedString(pw5);
911         FreeDuplicatedString(pw6);
912         return r;
913 }
914
915 BOOL GetSaveFileNameM(LPOPENFILENAMEA v0)
916 {
917         BOOL r = FALSE;
918         wchar_t* pw0 = NULL;
919         wchar_t* pw1 = NULL;
920         wchar_t* pw2 = NULL;
921         wchar_t* pw3 = NULL;
922         wchar_t* pw4 = NULL;
923         wchar_t* pw5 = NULL;
924         wchar_t* pw6 = NULL;
925         wchar_t* pw7 = NULL;
926         wchar_t* pw8 = NULL;
927         wchar_t* pw9 = NULL;
928         OPENFILENAMEW wofn;
929 START_ROUTINE
930         wofn.lStructSize = sizeof(OPENFILENAMEW);
931         wofn.hwndOwner = v0->hwndOwner;
932         wofn.hInstance = v0->hInstance;
933         pw0 = DuplicateMtoWMultiString(v0->lpstrFilter);
934         wofn.lpstrFilter = pw0;
935         pw1 = DuplicateMtoWBuffer(v0->lpstrCustomFilter, -1, v0->nMaxCustFilter * 4);
936         wofn.lpstrCustomFilter = pw1;
937         wofn.nMaxCustFilter = v0->nMaxCustFilter * 4;
938         wofn.nFilterIndex = v0->nFilterIndex;
939         pw2 = DuplicateMtoWMultiStringBuffer(v0->lpstrFile, v0->nMaxFile * 4);
940         wofn.lpstrFile = pw2;
941         wofn.nMaxFile = v0->nMaxFile * 4;
942         pw3 = DuplicateMtoWBuffer(v0->lpstrFileTitle, -1, v0->nMaxFileTitle * 4);
943         wofn.lpstrFileTitle = pw3;
944         wofn.nMaxFileTitle = v0->nMaxFileTitle * 4;
945         pw4 = DuplicateMtoW(v0->lpstrInitialDir, -1);
946         wofn.lpstrInitialDir = pw4;
947         pw5 = DuplicateMtoW(v0->lpstrTitle, -1);
948         wofn.lpstrTitle = pw5;
949         wofn.Flags = v0->Flags;
950         wofn.nFileOffset = MtoW(NULL, 0, v0->lpstrFile, v0->nFileOffset);
951         wofn.nFileExtension = MtoW(NULL, 0, v0->lpstrFile, v0->nFileExtension);
952         pw6 = DuplicateMtoW(v0->lpstrDefExt, -1);
953         wofn.lpstrDefExt = pw6;
954         wofn.lCustData = v0->lCustData;
955         wofn.lpfnHook = v0->lpfnHook;
956         wofn.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);
957         wofn.pvReserved = v0->pvReserved;
958         wofn.FlagsEx = v0->FlagsEx;
959         r = GetSaveFileNameW(&wofn);
960         WtoM(v0->lpstrFile, v0->nMaxFile, wofn.lpstrFile, -1);
961         TerminateStringM(v0->lpstrFile, v0->nMaxFile);
962         v0->nFileOffset = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileOffset);
963         v0->nFileExtension = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileExtension);
964 END_ROUTINE
965         FreeDuplicatedString(pw0);
966         FreeDuplicatedString(pw1);
967         FreeDuplicatedString(pw2);
968         FreeDuplicatedString(pw3);
969         FreeDuplicatedString(pw4);
970         FreeDuplicatedString(pw5);
971         FreeDuplicatedString(pw6);
972         return r;
973 }
974
975 HWND HtmlHelpM(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData)
976 {
977         HINSTANCE r = NULL;
978         wchar_t* pw0 = NULL;
979 START_ROUTINE
980         pw0 = DuplicateMtoW(pszFile, -1);
981         r = HtmlHelpW(hwndCaller, pw0, uCommand, dwData);
982 END_ROUTINE
983         FreeDuplicatedString(pw0);
984         return r;
985 }
986
987 HINSTANCE ShellExecuteM(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd)
988 {
989         HINSTANCE r = NULL;
990         wchar_t* pw0 = NULL;
991         wchar_t* pw1 = NULL;
992         wchar_t* pw2 = NULL;
993         wchar_t* pw3 = NULL;
994 START_ROUTINE
995         pw0 = DuplicateMtoW(lpOperation, -1);
996         pw1 = DuplicateMtoW(lpFile, -1);
997         pw2 = DuplicateMtoW(lpParameters, -1);
998         pw3 = DuplicateMtoW(lpDirectory, -1);
999         r = ShellExecuteW(hwnd, pw0, pw1, pw2, pw3, nShowCmd);
1000 END_ROUTINE
1001         FreeDuplicatedString(pw0);
1002         FreeDuplicatedString(pw1);
1003         FreeDuplicatedString(pw2);
1004         FreeDuplicatedString(pw3);
1005         return r;
1006 }
1007
1008 PIDLIST_ABSOLUTE SHBrowseForFolderM(LPBROWSEINFOA lpbi)
1009 {
1010         PIDLIST_ABSOLUTE r = NULL;
1011         wchar_t* pw0 = NULL;
1012         wchar_t* pw1 = NULL;
1013         BROWSEINFOW wbi;
1014 START_ROUTINE
1015         wbi.hwndOwner = lpbi->hwndOwner;
1016         wbi.pidlRoot = lpbi->pidlRoot;
1017         pw0 = DuplicateMtoWBuffer(lpbi->pszDisplayName, -1, MAX_PATH * 4);
1018         wbi.pszDisplayName = pw0;
1019         pw1 = DuplicateMtoW(lpbi->lpszTitle, -1);
1020         wbi.lpszTitle = pw1;
1021         wbi.ulFlags = lpbi->ulFlags;
1022         // TODO: lpfn
1023         wbi.lpfn = lpbi->lpfn;
1024         wbi.lParam = lpbi->lParam;
1025         wbi.iImage = lpbi->iImage;
1026         r = SHBrowseForFolderW(&wbi);
1027         // \83o\83b\83t\83@\92·\95s\96¾\82Ì\82½\82ß\83I\81[\83o\81[\83\89\83\93\82Ì\89Â\94\\90«\82 \82è
1028         WtoM(lpbi->pszDisplayName, MAX_PATH, wbi.pszDisplayName, -1);
1029         lpbi->iImage = wbi.iImage;
1030 END_ROUTINE
1031         FreeDuplicatedString(pw0);
1032         FreeDuplicatedString(pw1);
1033         return r;
1034 }
1035
1036 BOOL SHGetPathFromIDListM(PCIDLIST_ABSOLUTE pidl, LPSTR pszPath)
1037 {
1038         BOOL r = FALSE;
1039         wchar_t* pw0 = NULL;
1040 START_ROUTINE
1041         pw0 = AllocateStringW(MAX_PATH * 4);
1042         r = SHGetPathFromIDListW(pidl, pw0);
1043         // \83o\83b\83t\83@\92·\95s\96¾\82Ì\82½\82ß\83I\81[\83o\81[\83\89\83\93\82Ì\89Â\94\\90«\82 \82è
1044         WtoM(pszPath, MAX_PATH, pw0, -1);
1045         TerminateStringM(pszPath, MAX_PATH);
1046 END_ROUTINE
1047         FreeDuplicatedString(pw0);
1048         return r;
1049 }
1050
1051 int SHFileOperationM(LPSHFILEOPSTRUCTA lpFileOp)
1052 {
1053         int r = 0;
1054         wchar_t* pw0 = NULL;
1055         wchar_t* pw1 = NULL;
1056         wchar_t* pw2 = NULL;
1057         SHFILEOPSTRUCTW wFileOp;
1058 START_ROUTINE
1059         wFileOp.hwnd = lpFileOp->hwnd;
1060         wFileOp.wFunc = lpFileOp->wFunc;
1061         pw0 = DuplicateMtoWMultiString(lpFileOp->pFrom);
1062         wFileOp.pFrom = pw0;
1063         pw1 = DuplicateMtoWMultiString(lpFileOp->pTo);
1064         wFileOp.pTo = pw1;
1065         wFileOp.fFlags = lpFileOp->fFlags;
1066         wFileOp.fAnyOperationsAborted = lpFileOp->fAnyOperationsAborted;
1067         wFileOp.hNameMappings = lpFileOp->hNameMappings;
1068         pw2 = DuplicateMtoW(lpFileOp->lpszProgressTitle, -1);
1069         r = SHFileOperationW(&wFileOp);
1070         lpFileOp->fAnyOperationsAborted = wFileOp.fAnyOperationsAborted;
1071 END_ROUTINE
1072         FreeDuplicatedString(pw0);
1073         FreeDuplicatedString(pw1);
1074         FreeDuplicatedString(pw2);
1075         return r;
1076 }
1077
1078 BOOL AppendMenuM(HMENU hMenu, UINT uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem)
1079 {
1080         int r = 0;
1081         wchar_t* pw0 = NULL;
1082 START_ROUTINE
1083         if(uFlags & (MF_BITMAP | MF_OWNERDRAW))
1084                 r = AppendMenuW(hMenu, uFlags, uIDNewItem, (LPCWSTR)lpNewItem);
1085         else
1086         {
1087                 pw0 = DuplicateMtoW(lpNewItem, -1);
1088                 r = AppendMenuW(hMenu, uFlags, uIDNewItem, pw0);
1089         }
1090 END_ROUTINE
1091         FreeDuplicatedString(pw0);
1092         return r;
1093 }
1094
1095 BOOL GetMenuItemInfoM(HMENU hmenu, UINT item, BOOL fByPosition, LPMENUITEMINFOA lpmii)
1096 {
1097         BOOL r = FALSE;
1098         wchar_t* pw0 = NULL;
1099         MENUITEMINFOW wmii;
1100 START_ROUTINE
1101         wmii.cbSize = sizeof(MENUITEMINFOW);
1102         wmii.fMask = lpmii->fMask;
1103         wmii.fType = lpmii->fType;
1104         wmii.fState = lpmii->fState;
1105         wmii.wID = lpmii->wID;
1106         wmii.hSubMenu = lpmii->hSubMenu;
1107         wmii.hbmpChecked = lpmii->hbmpChecked;
1108         wmii.hbmpUnchecked = lpmii->hbmpUnchecked;
1109         wmii.dwItemData = lpmii->dwItemData;
1110         pw0 = DuplicateMtoWBuffer(lpmii->dwTypeData, -1, lpmii->cch * 4);
1111         wmii.dwTypeData = pw0;
1112         wmii.cch = lpmii->cch * 4;
1113         r = GetMenuItemInfoW(hmenu, item, fByPosition, &wmii);
1114         lpmii->fType = wmii.fType;
1115         lpmii->fState = wmii.fState;
1116         lpmii->wID = wmii.wID;
1117         lpmii->hSubMenu = wmii.hSubMenu;
1118         lpmii->hbmpChecked = wmii.hbmpChecked;
1119         lpmii->hbmpUnchecked = wmii.hbmpUnchecked;
1120         lpmii->dwItemData = wmii.dwItemData;
1121         WtoM(lpmii->dwTypeData, lpmii->cch, wmii.dwTypeData, -1);
1122         TerminateStringM(lpmii->dwTypeData, lpmii->cch);
1123 END_ROUTINE
1124         FreeDuplicatedString(pw0);
1125         return r;
1126 }
1127
1128 HFONT CreateFontIndirectM(CONST LOGFONTA *lplf)
1129 {
1130         HFONT r = NULL;
1131         LOGFONTW wlf;
1132 START_ROUTINE
1133         wlf.lfHeight = lplf->lfHeight;
1134         wlf.lfWidth = lplf->lfWidth;
1135         wlf.lfEscapement = lplf->lfEscapement;
1136         wlf.lfOrientation = lplf->lfOrientation;
1137         wlf.lfWeight = lplf->lfWeight;
1138         wlf.lfItalic = lplf->lfItalic;
1139         wlf.lfUnderline = lplf->lfUnderline;
1140         wlf.lfStrikeOut = lplf->lfStrikeOut;
1141         wlf.lfCharSet = lplf->lfCharSet;
1142         wlf.lfOutPrecision = lplf->lfOutPrecision;
1143         wlf.lfClipPrecision = lplf->lfClipPrecision;
1144         wlf.lfQuality = lplf->lfQuality;
1145         wlf.lfPitchAndFamily = lplf->lfPitchAndFamily;
1146         MtoW(wlf.lfFaceName, LF_FACESIZE, lplf->lfFaceName, -1);
1147         TerminateStringW(wlf.lfFaceName, LF_FACESIZE);
1148         r = CreateFontIndirect(&wlf);
1149 END_ROUTINE
1150         return r;
1151 }
1152
1153 BOOL ChooseFontM(LPCHOOSEFONTA v0)
1154 {
1155         BOOL r = FALSE;
1156         wchar_t* pw0 = NULL;
1157         CHOOSEFONTW a0;
1158         LOGFONTW* pwlf;
1159 START_ROUTINE
1160         a0.lStructSize = sizeof(CHOOSEFONTW);
1161         a0.hwndOwner = v0->hwndOwner;
1162         a0.hDC = v0->hDC;
1163         if(v0->lpLogFont && (pwlf = (LOGFONTW*)malloc(sizeof(LOGFONTW))))
1164         {
1165                 pwlf->lfHeight = v0->lpLogFont->lfHeight;
1166                 pwlf->lfWidth = v0->lpLogFont->lfWidth;
1167                 pwlf->lfEscapement = v0->lpLogFont->lfEscapement;
1168                 pwlf->lfOrientation = v0->lpLogFont->lfOrientation;
1169                 pwlf->lfWeight = v0->lpLogFont->lfWeight;
1170                 pwlf->lfItalic = v0->lpLogFont->lfItalic;
1171                 pwlf->lfUnderline = v0->lpLogFont->lfUnderline;
1172                 pwlf->lfStrikeOut = v0->lpLogFont->lfStrikeOut;
1173                 pwlf->lfCharSet = v0->lpLogFont->lfCharSet;
1174                 pwlf->lfOutPrecision = v0->lpLogFont->lfOutPrecision;
1175                 pwlf->lfClipPrecision = v0->lpLogFont->lfClipPrecision;
1176                 pwlf->lfQuality = v0->lpLogFont->lfQuality;
1177                 pwlf->lfPitchAndFamily = v0->lpLogFont->lfPitchAndFamily;
1178                 MtoW(pwlf->lfFaceName, LF_FACESIZE, v0->lpLogFont->lfFaceName, -1);
1179                 TerminateStringW(pwlf->lfFaceName, LF_FACESIZE);
1180         }
1181         else
1182                 pwlf = NULL;
1183         a0.lpLogFont = pwlf;
1184         a0.iPointSize = v0->iPointSize;
1185         a0.Flags = v0->Flags;
1186         a0.rgbColors = v0->rgbColors;
1187         a0.lCustData = v0->lCustData;
1188         a0.lpfnHook = v0->lpfnHook;
1189         a0.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);
1190         a0.hInstance = v0->hInstance;
1191         a0.lpszStyle = DuplicateMtoWBuffer(v0->lpszStyle, -1, LF_FACESIZE * 4);
1192         a0.nFontType = v0->nFontType;
1193         a0.nSizeMin = v0->nSizeMin;
1194         a0.nSizeMax = v0->nSizeMax;
1195         r = ChooseFontW(&a0);
1196         if(v0->lpLogFont)
1197         {
1198                 v0->lpLogFont->lfHeight = pwlf->lfHeight;
1199                 v0->lpLogFont->lfWidth = pwlf->lfWidth;
1200                 v0->lpLogFont->lfEscapement = pwlf->lfEscapement;
1201                 v0->lpLogFont->lfOrientation = pwlf->lfOrientation;
1202                 v0->lpLogFont->lfWeight = pwlf->lfWeight;
1203                 v0->lpLogFont->lfItalic = pwlf->lfItalic;
1204                 v0->lpLogFont->lfUnderline = pwlf->lfUnderline;
1205                 v0->lpLogFont->lfStrikeOut = pwlf->lfStrikeOut;
1206                 v0->lpLogFont->lfCharSet = pwlf->lfCharSet;
1207                 v0->lpLogFont->lfOutPrecision = pwlf->lfOutPrecision;
1208                 v0->lpLogFont->lfClipPrecision = pwlf->lfClipPrecision;
1209                 v0->lpLogFont->lfQuality = pwlf->lfQuality;
1210                 v0->lpLogFont->lfPitchAndFamily = pwlf->lfPitchAndFamily;
1211                 WtoM(v0->lpLogFont->lfFaceName, LF_FACESIZE, pwlf->lfFaceName, -1);
1212                 TerminateStringM(v0->lpLogFont->lfFaceName, LF_FACESIZE);
1213         }
1214         v0->rgbColors = a0.rgbColors;
1215         WtoM(v0->lpszStyle, LF_FACESIZE, a0.lpszStyle, -1);
1216         TerminateStringM(v0->lpszStyle, LF_FACESIZE);
1217         v0->nFontType = a0.nFontType;
1218         if(pwlf)
1219                 free(pwlf);
1220         FreeDuplicatedString(a0.lpTemplateName);
1221         FreeDuplicatedString(a0.lpszStyle);
1222 END_ROUTINE
1223         FreeDuplicatedString(pw0);
1224         return r;
1225 }
1226
1227
1228
1229
1230
1231
1232
1233