2 // Copyright (C) 2011 Suguru Kawamoto
3 // マルチバイト文字ワイド文字APIラッパー
4 // マルチバイト文字はUTF-8、ワイド文字はUTF-16であるものとする
5 // 全ての制御用の文字はASCIIの範囲であるため、Shift_JISとUTF-8間の変換は不要
9 #define _WIN32_WINNT 0x0600
11 #define _WIN32_IE 0x0400
20 #define DO_NOT_REPLACE
21 #include "mbswrapper.h"
23 // マルチバイト文字列からワイド文字列へ変換
24 int MtoW(LPWSTR pDst, int size, LPCSTR pSrc, int count)
26 if(pSrc < (LPCSTR)0x00010000 || pSrc == (LPCSTR)~0)
29 return MultiByteToWideChar(CP_UTF8, 0, pSrc, count, pDst, size);
30 return MultiByteToWideChar(CP_UTF8, 0, pSrc, count, NULL, 0);
33 // ワイド文字列からマルチバイト文字列へ変換
34 int WtoM(LPSTR pDst, int size, LPCWSTR pSrc, int count)
36 if(pSrc < (LPCWSTR)0x00010000 || pSrc == (LPCWSTR)~0)
39 return WideCharToMultiByte(CP_UTF8, 0, pSrc, count, pDst, size, NULL, NULL);
40 return WideCharToMultiByte(CP_UTF8, 0, pSrc, count, NULL, 0, NULL, NULL);
43 // ワイド文字列からShift_JIS文字列へ変換
44 int WtoA(LPSTR pDst, int size, LPCWSTR pSrc, int count)
46 if(pSrc < (LPCWSTR)0x00010000 || pSrc == (LPCWSTR)~0)
49 return WideCharToMultiByte(CP_ACP, 0, pSrc, count, pDst, size, NULL, NULL);
50 return WideCharToMultiByte(CP_ACP, 0, pSrc, count, NULL, 0, NULL, NULL);
53 // マルチバイト文字列バッファ終端を強制的にNULLで置換
54 int TerminateStringM(LPSTR lpString, int size)
57 if(lpString < (LPSTR)0x00010000 || lpString == (LPSTR)~0)
59 for(i = 0; i < size; i++)
61 if(lpString[i] == '\0')
69 // ワイド文字列バッファ終端を強制的にNULLで置換
70 int TerminateStringW(LPWSTR lpString, int size)
73 if(lpString < (LPWSTR)0x00010000 || lpString == (LPWSTR)~0)
75 for(i = 0; i < size; i++)
77 if(lpString[i] == L'\0')
85 // Shift_JIS文字列バッファ終端を強制的にNULLで置換
86 int TerminateStringA(LPSTR lpString, int size)
89 if(lpString < (LPSTR)0x00010000 || lpString == (LPSTR)~0)
91 for(i = 0; i < size; i++)
93 if(lpString[i] == '\0')
101 // NULL区切り複数マルチバイト文字列の長さを取得
102 size_t GetMultiStringLengthM(LPCSTR lpString)
105 if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)
108 while(lpString[i] != '\0' || lpString[i + 1] != '\0')
116 // NULL区切り複数ワイド文字列の長さを取得
117 size_t GetMultiStringLengthW(LPCWSTR lpString)
120 if(lpString < (LPCWSTR)0x00010000 || lpString == (LPCWSTR)~0)
123 while(lpString[i] != L'\0' || lpString[i + 1] != L'\0')
131 // NULL区切り複数Shift_JIS文字列の長さを取得
132 size_t GetMultiStringLengthA(LPCSTR lpString)
135 if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)
138 while(lpString[i] != '\0' || lpString[i + 1] != '\0')
146 // NULL区切りマルチバイト文字列からワイド文字列へ変換
147 int MtoWMultiString(LPWSTR pDst, int size, LPCSTR pSrc)
150 if(pSrc < (LPCSTR)0x00010000 || pSrc == (LPCSTR)~0)
153 return GetMultiStringLengthM(pSrc);
157 i += MultiByteToWideChar(CP_UTF8, 0, pSrc, -1, pDst + i, size - i - 1);
158 pSrc += strlen(pSrc) + 1;
164 // NULL区切りワイド文字列からマルチバイト文字列へ変換
165 int WtoMMultiString(LPSTR pDst, int size, LPCWSTR pSrc)
168 if(pSrc < (LPCWSTR)0x00010000 || pSrc == (LPCWSTR)~0)
171 return GetMultiStringLengthW(pSrc);
173 while(*pSrc != L'\0')
175 i += WideCharToMultiByte(CP_UTF8, 0, pSrc, -1, pDst + i, size - i - 1, NULL, NULL);
176 pSrc += wcslen(pSrc) + 1;
182 // NULL区切りワイド文字列からShift_JIS文字列へ変換
183 int WtoAMultiString(LPSTR pDst, int size, LPCWSTR pSrc)
186 if(pSrc < (LPCWSTR)0x00010000 || pSrc == (LPCWSTR)~0)
189 return GetMultiStringLengthW(pSrc);
191 while(*pSrc != L'\0')
193 i += WideCharToMultiByte(CP_ACP, 0, pSrc, -1, pDst + i, size - i - 1, NULL, NULL);
194 pSrc += wcslen(pSrc) + 1;
201 char* AllocateStringM(int size)
204 // 0が指定される場合があるため1文字分追加
205 p = (char*)malloc(sizeof(char) * (size + 1));
213 wchar_t* AllocateStringW(int size)
216 // 0が指定される場合があるため1文字分追加
217 p = (wchar_t*)malloc(sizeof(wchar_t) * (size + 1));
224 // Shift_JIS文字列用のメモリを確保
225 char* AllocateStringA(int size)
228 // 0が指定される場合があるため1文字分追加
229 p = (char*)malloc(sizeof(char) * (size + 1));
236 // メモリを確保してマルチバイト文字列からワイド文字列へ変換
237 wchar_t* DuplicateMtoW(LPCSTR lpString, int c)
241 if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)
242 return (wchar_t*)lpString;
244 c = strlen(lpString);
245 p = AllocateStringW(MtoW(NULL, 0, lpString, c) + 1);
248 i = MtoW(p, 65535, lpString, c);
254 // 指定したサイズのメモリを確保してマルチバイト文字列からワイド文字列へ変換
255 wchar_t* DuplicateMtoWBuffer(LPCSTR lpString, int c, int size)
259 if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)
260 return (wchar_t*)lpString;
262 c = strlen(lpString);
263 p = AllocateStringW(size);
266 i = MtoW(p, size, lpString, c);
272 // メモリを確保してNULL区切りマルチバイト文字列からワイド文字列へ変換
273 wchar_t* DuplicateMtoWMultiString(LPCSTR lpString)
277 if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)
278 return (wchar_t*)lpString;
279 count = GetMultiStringLengthM(lpString) + 1;
280 p = AllocateStringW(count);
282 MtoW(p, count, lpString, count);
286 // 指定したサイズのメモリを確保してNULL区切りマルチバイト文字列からワイド文字列へ変換
287 wchar_t* DuplicateMtoWMultiStringBuffer(LPCSTR lpString, int size)
291 if(lpString < (LPCSTR)0x00010000 || lpString == (LPCSTR)~0)
292 return (wchar_t*)lpString;
293 count = GetMultiStringLengthM(lpString) + 1;
294 p = AllocateStringW(size);
297 MtoW(p, size, lpString, count);
304 // メモリを確保してワイド文字列からマルチバイト文字列へ変換
305 char* DuplicateWtoM(LPCWSTR lpString, int c)
309 if(lpString < (LPCWSTR)0x00010000 || lpString == (LPCWSTR)~0)
310 return (char*)lpString;
312 c = wcslen(lpString);
313 p = AllocateStringM(WtoM(NULL, 0, lpString, c) + 1);
316 i = WtoM(p, 65535, lpString, c);
322 // メモリを確保してワイド文字列からShift_JIS文字列へ変換
323 char* DuplicateWtoA(LPCWSTR lpString, int c)
327 if(lpString < (LPCWSTR)0x00010000 || lpString == (LPCWSTR)~0)
328 return (char*)lpString;
330 c = wcslen(lpString);
331 p = AllocateStringA(WtoA(NULL, 0, lpString, c) + 1);
334 i = WtoA(p, 65535, lpString, c);
341 void FreeDuplicatedString(void* p)
343 if(p < (void*)0x00010000 || p == (void*)~0)
354 #define START_ROUTINE do{
355 #define END_ROUTINE }while(0);end_of_routine:
356 #define QUIT_ROUTINE goto end_of_routine;
358 int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
363 pm0 = DuplicateWtoM(lpCmdLine, -1);
364 r = WinMainM(hInstance, hPrevInstance, pm0, nCmdShow);
366 FreeDuplicatedString(pm0);
370 HANDLE CreateFileM(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
372 HANDLE r = INVALID_HANDLE_VALUE;
375 pw0 = DuplicateMtoW(lpFileName, -1);
376 r = CreateFileW(pw0, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
378 FreeDuplicatedString(pw0);
382 int MessageBoxM(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
388 pw0 = DuplicateMtoW(lpText, -1);
389 pw1 = DuplicateMtoW(lpCaption, -1);
390 r = MessageBoxW(hWnd, pw0, pw1, uType);
392 FreeDuplicatedString(pw0);
393 FreeDuplicatedString(pw1);
397 HANDLE FindFirstFileM(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
399 HANDLE r = INVALID_HANDLE_VALUE;
403 pw0 = DuplicateMtoW(lpFileName, -1);
404 r = FindFirstFileW(pw0, &a0);
405 if(r != INVALID_HANDLE_VALUE)
407 lpFindFileData->dwFileAttributes = a0.dwFileAttributes;
408 lpFindFileData->ftCreationTime = a0.ftCreationTime;
409 lpFindFileData->ftLastAccessTime = a0.ftLastAccessTime;
410 lpFindFileData->ftLastWriteTime = a0.ftLastWriteTime;
411 lpFindFileData->nFileSizeHigh = a0.nFileSizeHigh;
412 lpFindFileData->nFileSizeLow = a0.nFileSizeLow;
413 lpFindFileData->dwReserved0 = a0.dwReserved0;
414 lpFindFileData->dwReserved1 = a0.dwReserved1;
415 WtoM(lpFindFileData->cFileName, sizeof(lpFindFileData->cFileName), a0.cFileName, -1);
416 WtoM(lpFindFileData->cAlternateFileName, sizeof(lpFindFileData->cAlternateFileName), a0.cAlternateFileName, -1);
419 FreeDuplicatedString(pw0);
423 BOOL FindNextFileM(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData)
428 r = FindNextFileW(hFindFile, &a0);
431 lpFindFileData->dwFileAttributes = a0.dwFileAttributes;
432 lpFindFileData->ftCreationTime = a0.ftCreationTime;
433 lpFindFileData->ftLastAccessTime = a0.ftLastAccessTime;
434 lpFindFileData->ftLastWriteTime = a0.ftLastWriteTime;
435 lpFindFileData->nFileSizeHigh = a0.nFileSizeHigh;
436 lpFindFileData->nFileSizeLow = a0.nFileSizeLow;
437 lpFindFileData->dwReserved0 = a0.dwReserved0;
438 lpFindFileData->dwReserved1 = a0.dwReserved1;
439 WtoM(lpFindFileData->cFileName, sizeof(lpFindFileData->cFileName), a0.cFileName, -1);
440 WtoM(lpFindFileData->cAlternateFileName, sizeof(lpFindFileData->cAlternateFileName), a0.cAlternateFileName, -1);
446 DWORD GetLogicalDriveStringsM(DWORD nBufferLength, LPSTR lpBuffer)
451 pw0 = AllocateStringW(nBufferLength * 4);
452 GetLogicalDriveStringsW(nBufferLength * 4, pw0);
453 WtoMMultiString(lpBuffer, nBufferLength, pw0);
454 r = TerminateStringM(lpBuffer, nBufferLength);
456 FreeDuplicatedString(pw0);
460 ATOM RegisterClassExM(CONST WNDCLASSEXA * v0)
464 // WNDPROCがShift_JIS用であるため
465 r = RegisterClassExA(v0);
470 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)
476 pw0 = DuplicateMtoW(lpClassName, -1);
477 pw1 = DuplicateMtoW(lpWindowName, -1);
478 r = CreateWindowExW(dwExStyle, pw0, pw1, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
480 FreeDuplicatedString(pw0);
481 FreeDuplicatedString(pw1);
485 LONG GetWindowLongM(HWND hWnd, int nIndex)
489 // WNDPROCがShift_JIS用であるため
490 if(IsWindowUnicode(hWnd))
491 r = GetWindowLongW(hWnd, nIndex);
493 r = GetWindowLongA(hWnd, nIndex);
498 LONG SetWindowLongM(HWND hWnd, int nIndex, LONG dwNewLong)
502 // WNDPROCがShift_JIS用であるため
503 if(IsWindowUnicode(hWnd))
504 r = SetWindowLongW(hWnd, nIndex, dwNewLong);
506 r = SetWindowLongA(hWnd, nIndex, dwNewLong);
511 LRESULT DefWindowProcM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
515 // WNDPROCがShift_JIS用であるため
516 if(IsWindowUnicode(hWnd))
517 r = DefWindowProcW(hWnd, Msg, wParam, lParam);
519 r = DefWindowProcA(hWnd, Msg, wParam, lParam);
524 LRESULT CallWindowProcM(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
528 // WNDPROCがShift_JIS用であるため
529 if(IsWindowUnicode(hWnd))
530 r = CallWindowProcW(lpPrevWndFunc, hWnd, Msg, wParam, lParam);
532 r = CallWindowProcA(lpPrevWndFunc, hWnd, Msg, wParam, lParam);
537 LRESULT SendMessageM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
545 LVFINDINFOA* pmLVFindInfo;
546 LVFINDINFOW wLVFindInfo;
547 LVCOLUMNA* pmLVColumn;
549 wchar_t ClassName[MAX_PATH];
554 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
555 r = SendMessageW(hWnd, WM_SETTEXT, wParam, (LPARAM)pw0);
558 pw0 = AllocateStringW(wParam * 4);
559 SendMessageW(hWnd, WM_GETTEXT, wParam * 4, (LPARAM)pw0);
560 WtoM((LPSTR)lParam, wParam, pw0, -1);
561 r = TerminateStringM((LPSTR)lParam, wParam);
563 case WM_GETTEXTLENGTH:
564 Size = SendMessageW(hWnd, WM_GETTEXTLENGTH, wParam, lParam) + 1;
565 pw0 = AllocateStringW(Size);
566 SendMessageW(hWnd, WM_GETTEXT, (WPARAM)Size, (LPARAM)pw0);
567 r = WtoM(NULL, 0, pw0, -1) - 1;
570 GetClassNameW(hWnd, ClassName, sizeof(ClassName) / sizeof(wchar_t));
571 if(_wcsicmp(ClassName, WC_EDITW) == 0)
576 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
577 r = SendMessageW(hWnd, EM_REPLACESEL, wParam, (LPARAM)pw0);
580 r = SendMessageW(hWnd, Msg, wParam, lParam);
584 else if(_wcsicmp(ClassName, WC_COMBOBOXW) == 0)
589 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
590 r = SendMessageW(hWnd, CB_ADDSTRING, wParam, (LPARAM)pw0);
593 Size = SendMessageW(hWnd, CB_GETLBTEXTLEN, wParam, 0) + 1;
594 pw0 = AllocateStringW(Size);
595 SendMessageW(hWnd, CB_GETLBTEXT, wParam, (LPARAM)pw0);
596 // バッファ長不明のためオーバーランの可能性あり
597 WtoM((LPSTR)lParam, Size * 4, pw0, -1);
598 r = TerminateStringM((LPSTR)lParam, Size * 4);
600 case CB_GETLBTEXTLEN:
601 Size = SendMessageW(hWnd, CB_GETLBTEXTLEN, wParam, 0) + 1;
602 pw0 = AllocateStringW(Size);
603 SendMessageW(hWnd, WM_GETTEXT, wParam, (LPARAM)pw0);
604 r = WtoM(NULL, 0, pw0, -1) - 1;
606 case CB_INSERTSTRING:
607 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
608 r = SendMessageW(hWnd, CB_INSERTSTRING, wParam, (LPARAM)pw0);
610 case CB_FINDSTRINGEXACT:
611 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
612 r = SendMessageW(hWnd, CB_FINDSTRINGEXACT, wParam, (LPARAM)pw0);
615 r = SendMessageW(hWnd, Msg, wParam, lParam);
619 else if(_wcsicmp(ClassName, WC_LISTBOXW) == 0)
624 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
625 r = SendMessageW(hWnd, LB_ADDSTRING, wParam, (LPARAM)pw0);
627 case LB_INSERTSTRING:
628 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
629 r = SendMessageW(hWnd, LB_INSERTSTRING, wParam, (LPARAM)pw0);
632 Size = SendMessageW(hWnd, LB_GETTEXTLEN, wParam, 0) + 1;
633 pw0 = AllocateStringW(Size);
634 SendMessageW(hWnd, LB_GETTEXT, wParam, (LPARAM)pw0);
635 // バッファ長不明のためオーバーランの可能性あり
636 WtoM((LPSTR)lParam, Size * 4, pw0, -1);
637 r = TerminateStringM((LPSTR)lParam, Size * 4);
640 Size = SendMessageW(hWnd, LB_GETTEXTLEN, wParam, 0) + 1;
641 pw0 = AllocateStringW(Size);
642 SendMessageW(hWnd, WM_GETTEXT, wParam, (LPARAM)pw0);
643 r = WtoM(NULL, 0, pw0, -1) - 1;
646 r = SendMessageW(hWnd, Msg, wParam, lParam);
650 else if(_wcsicmp(ClassName, WC_LISTVIEWW) == 0)
655 pmLVItem = (LVITEMA*)lParam;
656 wLVItem.mask = pmLVItem->mask;
657 wLVItem.iItem = pmLVItem->iItem;
658 wLVItem.iSubItem = pmLVItem->iSubItem;
659 wLVItem.state = pmLVItem->state;
660 wLVItem.stateMask = pmLVItem->stateMask;
661 if(pmLVItem->mask & LVIF_TEXT)
663 Size = pmLVItem->cchTextMax * 4;
664 pw0 = AllocateStringW(Size);
665 wLVItem.pszText = pw0;
666 wLVItem.cchTextMax = Size;
668 wLVItem.iImage = pmLVItem->iImage;
669 wLVItem.lParam = pmLVItem->lParam;
670 wLVItem.iIndent = pmLVItem->iIndent;
671 r = SendMessageW(hWnd, LVM_GETITEMW, wParam, (LPARAM)&wLVItem);
672 pmLVItem->mask = wLVItem.mask;
673 pmLVItem->iItem = wLVItem.iItem;
674 pmLVItem->iSubItem = wLVItem.iSubItem;
675 pmLVItem->state = wLVItem.state;
676 pmLVItem->stateMask = wLVItem.stateMask;
677 if(pmLVItem->mask & LVIF_TEXT)
679 WtoM(pmLVItem->pszText, pmLVItem->cchTextMax, wLVItem.pszText, -1);
680 TerminateStringM(pmLVItem->pszText, pmLVItem->cchTextMax);
682 pmLVItem->iImage = wLVItem.iImage;
683 pmLVItem->lParam = wLVItem.lParam;
684 pmLVItem->iIndent = wLVItem.iIndent;
687 pmLVItem = (LVITEMA*)lParam;
688 wLVItem.mask = pmLVItem->mask;
689 wLVItem.iItem = pmLVItem->iItem;
690 wLVItem.iSubItem = pmLVItem->iSubItem;
691 wLVItem.state = pmLVItem->state;
692 wLVItem.stateMask = pmLVItem->stateMask;
693 if(pmLVItem->mask & LVIF_TEXT)
695 pw0 = DuplicateMtoW(pmLVItem->pszText, -1);
696 wLVItem.pszText = pw0;
697 // TODO: cchTextMaxの確認
698 wLVItem.cchTextMax = pmLVItem->cchTextMax;
700 wLVItem.iImage = pmLVItem->iImage;
701 wLVItem.lParam = pmLVItem->lParam;
702 wLVItem.iIndent = pmLVItem->iIndent;
703 r = SendMessageW(hWnd, LVM_SETITEMW, wParam, (LPARAM)&wLVItem);
705 case LVM_INSERTITEMA:
706 pmLVItem = (LVITEMA*)lParam;
707 wLVItem.mask = pmLVItem->mask;
708 wLVItem.iItem = pmLVItem->iItem;
709 wLVItem.iSubItem = pmLVItem->iSubItem;
710 wLVItem.state = pmLVItem->state;
711 wLVItem.stateMask = pmLVItem->stateMask;
712 if(pmLVItem->mask & LVIF_TEXT)
714 pw0 = DuplicateMtoW(pmLVItem->pszText, -1);
715 wLVItem.pszText = pw0;
716 // TODO: cchTextMaxの確認
717 wLVItem.cchTextMax = pmLVItem->cchTextMax;
719 wLVItem.iImage = pmLVItem->iImage;
720 wLVItem.lParam = pmLVItem->lParam;
721 wLVItem.iIndent = pmLVItem->iIndent;
722 r = SendMessageW(hWnd, LVM_INSERTITEMW, wParam, (LPARAM)&wLVItem);
725 pmLVFindInfo = (LVFINDINFOA*)lParam;
726 wLVFindInfo.flags = pmLVFindInfo->flags;
727 if(pmLVFindInfo->flags & (LVFI_STRING | LVFI_PARTIAL))
729 pw0 = DuplicateMtoW(pmLVFindInfo->psz, -1);
730 wLVFindInfo.psz = pw0;
732 wLVFindInfo.lParam = pmLVFindInfo->lParam;
733 wLVFindInfo.pt = pmLVFindInfo->pt;
734 wLVFindInfo.vkDirection = pmLVFindInfo->vkDirection;
735 r = SendMessageW(hWnd, LVM_FINDITEMW, wParam, (LPARAM)&wLVItem);
738 pmLVColumn = (LVCOLUMNA*)lParam;
739 wLVColumn.mask = pmLVColumn->mask;
740 wLVColumn.fmt = pmLVColumn->fmt;
741 wLVColumn.cx = pmLVColumn->cx;
742 Size = pmLVColumn->cchTextMax * 4;
743 if(pmLVColumn->mask & LVCF_TEXT)
745 pw0 = AllocateStringW(Size);
746 wLVColumn.pszText = pw0;
747 wLVColumn.cchTextMax = Size;
749 wLVColumn.iSubItem = pmLVColumn->iSubItem;
750 wLVColumn.iImage = pmLVColumn->iImage;
751 wLVColumn.iOrder = pmLVColumn->iOrder;
752 r = SendMessageW(hWnd, LVM_GETCOLUMNW, wParam, (LPARAM)&wLVColumn);
753 pmLVColumn->mask = wLVColumn.mask;
754 pmLVColumn->fmt = wLVColumn.fmt;
755 pmLVColumn->cx = wLVColumn.cx;
756 if(pmLVColumn->mask & LVCF_TEXT)
758 WtoM(pmLVColumn->pszText, pmLVColumn->cchTextMax, wLVColumn.pszText, -1);
759 TerminateStringM(pmLVColumn->pszText, pmLVColumn->cchTextMax);
761 pmLVColumn->iSubItem = wLVColumn.iSubItem;
762 pmLVColumn->iImage = wLVColumn.iImage;
763 pmLVColumn->iOrder = wLVColumn.iOrder;
765 case LVM_INSERTCOLUMNA:
766 pmLVColumn = (LVCOLUMNA*)lParam;
767 wLVColumn.mask = pmLVColumn->mask;
768 wLVColumn.fmt = pmLVColumn->fmt;
769 wLVColumn.cx = pmLVColumn->cx;
770 if(pmLVColumn->mask & LVCF_TEXT)
772 pw0 = DuplicateMtoW(pmLVColumn->pszText, -1);
773 wLVColumn.pszText = pw0;
774 // TODO: cchTextMaxの確認
775 wLVColumn.cchTextMax = pmLVColumn->cchTextMax;
777 wLVColumn.iSubItem = pmLVColumn->iSubItem;
778 wLVColumn.iImage = pmLVColumn->iImage;
779 wLVColumn.iOrder = pmLVColumn->iOrder;
780 r = SendMessageW(hWnd, LVM_INSERTCOLUMNW, wParam, (LPARAM)&wLVColumn);
782 case LVM_GETITEMTEXTA:
783 pmLVItem = (LVITEMA*)lParam;
784 wLVItem.mask = pmLVItem->mask;
785 wLVItem.iItem = pmLVItem->iItem;
786 wLVItem.iSubItem = pmLVItem->iSubItem;
787 wLVItem.state = pmLVItem->state;
788 wLVItem.stateMask = pmLVItem->stateMask;
789 Size = pmLVItem->cchTextMax * 4;
790 pw0 = AllocateStringW(Size);
791 wLVItem.pszText = pw0;
792 wLVItem.cchTextMax = Size;
793 wLVItem.iImage = pmLVItem->iImage;
794 wLVItem.lParam = pmLVItem->lParam;
795 wLVItem.iIndent = pmLVItem->iIndent;
796 r = SendMessageW(hWnd, LVM_GETITEMTEXTW, wParam, (LPARAM)&wLVItem);
797 pmLVItem->mask = wLVItem.mask;
798 pmLVItem->iItem = wLVItem.iItem;
799 pmLVItem->iSubItem = wLVItem.iSubItem;
800 pmLVItem->state = wLVItem.state;
801 pmLVItem->stateMask = wLVItem.stateMask;
802 WtoM(pmLVItem->pszText, pmLVItem->cchTextMax, wLVItem.pszText, -1);
803 TerminateStringM(pmLVItem->pszText, pmLVItem->cchTextMax);
804 pmLVItem->iImage = wLVItem.iImage;
805 pmLVItem->lParam = wLVItem.lParam;
806 pmLVItem->iIndent = wLVItem.iIndent;
809 r = SendMessageW(hWnd, Msg, wParam, lParam);
813 else if(_wcsicmp(ClassName, STATUSCLASSNAMEW) == 0)
818 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
819 r = SendMessageW(hWnd, SB_SETTEXTW, wParam, (LPARAM)pw0);
822 r = SendMessageW(hWnd, Msg, wParam, lParam);
827 r = SendMessageW(hWnd, Msg, wParam, lParam);
831 FreeDuplicatedString(pw0);
832 FreeDuplicatedString(pw1);
836 LRESULT DefDlgProcM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
840 // WNDPROCがShift_JIS用であるため
841 if(IsWindowUnicode(hWnd))
842 r = DefDlgProcW(hWnd, Msg, wParam, lParam);
844 r = DefDlgProcA(hWnd, Msg, wParam, lParam);
849 LRESULT SendDlgItemMessageM(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam)
853 r = SendMessageM(GetDlgItem(hDlg, nIDDlgItem), Msg, wParam, lParam);
858 BOOL SetWindowTextM(HWND hWnd, LPCSTR lpString)
863 pw0 = DuplicateMtoW(lpString, -1);
864 r = SetWindowTextW(hWnd, pw0);
866 FreeDuplicatedString(pw0);
870 UINT DragQueryFileM(HDROP hDrop, UINT iFile, LPSTR lpszFile, UINT cch)
875 if(iFile == (UINT)-1)
876 r = DragQueryFileW(hDrop, iFile, (LPWSTR)lpszFile, cch);
879 pw0 = AllocateStringW(cch * 4);
880 DragQueryFileW(hDrop, iFile, pw0, cch * 4);
881 WtoM(lpszFile, cch, pw0, -1);
882 r = TerminateStringM(lpszFile, cch);
885 FreeDuplicatedString(pw0);
889 DWORD GetCurrentDirectoryM(DWORD nBufferLength, LPSTR lpBuffer)
894 pw0 = AllocateStringW(nBufferLength * 4);
895 GetCurrentDirectoryW(nBufferLength * 4, pw0);
896 WtoM(lpBuffer, nBufferLength, pw0, -1);
897 r = TerminateStringM(lpBuffer, nBufferLength);
899 FreeDuplicatedString(pw0);
903 BOOL SetCurrentDirectoryM(LPCSTR lpPathName)
908 pw0 = DuplicateMtoW(lpPathName, -1);
909 r = SetCurrentDirectoryW(pw0);
911 FreeDuplicatedString(pw0);
915 BOOL SetDllDirectoryM(LPCSTR lpPathName)
920 pw0 = DuplicateMtoW(lpPathName, -1);
921 r = SetDllDirectoryW(pw0);
923 FreeDuplicatedString(pw0);
927 DWORD GetTempPathM(DWORD nBufferLength, LPSTR lpBuffer)
932 pw0 = AllocateStringW(nBufferLength * 4);
933 GetTempPathW(nBufferLength * 4, pw0);
934 WtoM(lpBuffer, nBufferLength, pw0, -1);
935 r = TerminateStringM(lpBuffer, nBufferLength);
937 FreeDuplicatedString(pw0);
941 DWORD GetFileAttributesM(LPCSTR lpFileName)
946 pw0 = DuplicateMtoW(lpFileName, -1);
947 r = GetFileAttributesW(pw0);
949 FreeDuplicatedString(pw0);
953 DWORD GetModuleFileNameM(HMODULE hModule, LPCH lpFilename, DWORD nSize)
958 pw0 = AllocateStringW(nSize * 4);
959 GetModuleFileNameW(hModule, pw0, nSize * 4);
960 WtoM(lpFilename, nSize, pw0, -1);
961 r = TerminateStringM(lpFilename, nSize);
963 FreeDuplicatedString(pw0);
967 LSTATUS RegOpenKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
972 pw0 = DuplicateMtoW(lpSubKey, -1);
973 r = RegOpenKeyExW(hKey, pw0, ulOptions, samDesired, phkResult);
975 FreeDuplicatedString(pw0);
979 LSTATUS RegCreateKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass, DWORD dwOptions, REGSAM samDesired, CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition)
985 pw0 = DuplicateMtoW(lpSubKey, -1);
986 pw1 = DuplicateMtoW(lpClass, -1);
987 r = RegCreateKeyExW(hKey, pw0, Reserved, pw1, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition);
989 FreeDuplicatedString(pw0);
990 FreeDuplicatedString(pw1);
994 LSTATUS RegDeleteValueM(HKEY hKey, LPCSTR lpValueName)
999 pw0 = DuplicateMtoW(lpValueName, -1);
1000 r = RegDeleteValueW(hKey, pw0);
1002 FreeDuplicatedString(pw0);
1006 LSTATUS RegQueryValueExM(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)
1009 wchar_t* pw0 = NULL;
1010 wchar_t* pw1 = NULL;
1014 pw0 = DuplicateMtoW(lpValueName, -1);
1015 if(RegQueryValueExW(hKey, pw0, NULL, &dwType, NULL, 0) == ERROR_SUCCESS)
1024 pw1 = AllocateStringW(*lpcbData / sizeof(char) * 4);
1025 wcbData = *lpcbData / sizeof(char) * 4;
1026 r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, (LPBYTE)pw1, &wcbData);
1028 *lpcbData = sizeof(char) * WtoM((char*)lpData, *lpcbData / sizeof(char), pw1, wcbData / sizeof(wchar_t));
1030 *lpcbData = sizeof(char) * WtoM(NULL, 0, pw1, wcbData / sizeof(wchar_t));
1034 r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, lpData, lpcbData);
1039 r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, lpData, lpcbData);
1041 FreeDuplicatedString(pw0);
1042 FreeDuplicatedString(pw1);
1046 LSTATUS RegSetValueExM(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE* lpData, DWORD cbData)
1049 wchar_t* pw0 = NULL;
1050 wchar_t* pw1 = NULL;
1053 pw0 = DuplicateMtoW(lpValueName, -1);
1059 wcbData = MtoW(NULL, 0, (char*)lpData, cbData / sizeof(char));
1060 pw1 = AllocateStringW(wcbData);
1061 MtoW(pw1, wcbData, (char*)lpData, cbData / sizeof(char));
1062 wcbData = sizeof(wchar_t) * wcbData;
1063 lpData = (BYTE*)pw1;
1067 r = RegSetValueExW(hKey, pw0, Reserved, dwType, lpData, cbData);
1069 FreeDuplicatedString(pw0);
1070 FreeDuplicatedString(pw1);
1074 BOOL TextOutM(HDC hdc, int x, int y, LPCSTR lpString, int c)
1077 wchar_t* pw0 = NULL;
1079 pw0 = DuplicateMtoW(lpString, c);
1080 r = TextOutW(hdc, x, y, pw0, wcslen(pw0));
1082 FreeDuplicatedString(pw0);
1086 BOOL GetTextExtentPoint32M(HDC hdc, LPCSTR lpString, int c, LPSIZE psizl)
1089 wchar_t* pw0 = NULL;
1091 pw0 = DuplicateMtoW(lpString, c);
1092 r = GetTextExtentPoint32W(hdc, pw0, wcslen(pw0), psizl);
1094 FreeDuplicatedString(pw0);
1098 INT_PTR PropertySheetM(LPCPROPSHEETHEADERA v0)
1101 PROPSHEETHEADERW a0;
1102 PROPSHEETPAGEW* pwPage;
1105 a0.dwSize = sizeof(PROPSHEETHEADERW);
1106 a0.dwFlags = v0->dwFlags;
1107 a0.hwndParent = v0->hwndParent;
1108 a0.hInstance = v0->hInstance;
1109 if(v0->dwFlags & PSH_USEICONID)
1110 a0.pszIcon = DuplicateMtoW(v0->pszIcon, -1);
1112 a0.hIcon = v0->hIcon;
1113 a0.pszCaption = DuplicateMtoW(v0->pszCaption, -1);
1114 a0.nPages = v0->nPages;
1115 a0.pStartPage = DuplicateMtoW(v0->pStartPage, -1);
1116 if(v0->ppsp && (pwPage = (PROPSHEETPAGEW*)malloc(sizeof(PROPSHEETPAGEW) * v0->nPages)))
1118 for(i = 0; i < v0->nPages; i++)
1120 pwPage[i].dwSize = sizeof(PROPSHEETPAGEW);
1121 pwPage[i].dwFlags = v0->ppsp[i].dwFlags;
1122 pwPage[i].hInstance = v0->ppsp[i].hInstance;
1123 pwPage[i].pszTemplate = DuplicateMtoW(v0->ppsp[i].pszTemplate, -1);
1124 if(v0->ppsp[i].dwFlags & PSP_USEICONID)
1125 pwPage[i].pszIcon = DuplicateMtoW(v0->ppsp[i].pszIcon, -1);
1127 pwPage[i].hIcon = v0->ppsp[i].hIcon;
1128 if(v0->ppsp[i].dwFlags & PSP_USETITLE)
1129 pwPage[i].pszTitle = DuplicateMtoW(v0->ppsp[i].pszTitle, -1);
1130 pwPage[i].pfnDlgProc = v0->ppsp[i].pfnDlgProc;
1131 pwPage[i].lParam = v0->ppsp[i].lParam;
1132 // TODO: pfnCallback
1133 pwPage[i].pfnCallback = v0->ppsp[i].pfnCallback;
1134 pwPage[i].pcRefParent = v0->ppsp[i].pcRefParent;
1135 // pwPage[i].pszHeaderTitle = DuplicateMtoW(v0->ppsp[i].pszHeaderTitle, -1);
1136 // pwPage[i].pszHeaderSubTitle = DuplicateMtoW(v0->ppsp[i].pszHeaderSubTitle, -1);
1137 pwPage[i].hActCtx = v0->ppsp[i].hActCtx;
1138 // pwPage[i].pszbmHeader = DuplicateMtoW(v0->ppsp[i].pszbmHeader, -1);
1144 a0.pfnCallback = v0->pfnCallback;
1145 r = PropertySheetW(&a0);
1146 if(a0.dwFlags & PSH_USEICONID)
1147 FreeDuplicatedString(a0.pszIcon);
1148 FreeDuplicatedString(a0.pszCaption);
1149 FreeDuplicatedString(a0.pStartPage);
1152 for(i = 0; i < v0->nPages; i++)
1154 FreeDuplicatedString(pwPage[i].pszTemplate);
1155 if(pwPage[i].dwFlags & PSP_USEICONID)
1156 FreeDuplicatedString(pwPage[i].pszIcon);
1157 if(pwPage[i].dwFlags & PSP_USETITLE)
1158 FreeDuplicatedString(pwPage[i].pszTitle);
1159 // FreeDuplicatedString(pwPage[i].pszHeaderTitle);
1160 // FreeDuplicatedString(pwPage[i].pszHeaderSubTitle);
1161 // FreeDuplicatedString(pwPage[i].pszbmHeader);
1169 BOOL GetOpenFileNameM(LPOPENFILENAMEA v0)
1172 wchar_t* pw0 = NULL;
1173 wchar_t* pw1 = NULL;
1174 wchar_t* pw2 = NULL;
1175 wchar_t* pw3 = NULL;
1176 wchar_t* pw4 = NULL;
1177 wchar_t* pw5 = NULL;
1178 wchar_t* pw6 = NULL;
1179 wchar_t* pw7 = NULL;
1180 wchar_t* pw8 = NULL;
1181 wchar_t* pw9 = NULL;
1184 wofn.lStructSize = sizeof(OPENFILENAMEW);
1185 wofn.hwndOwner = v0->hwndOwner;
1186 wofn.hInstance = v0->hInstance;
1187 pw0 = DuplicateMtoWMultiString(v0->lpstrFilter);
1188 wofn.lpstrFilter = pw0;
1189 pw1 = DuplicateMtoWBuffer(v0->lpstrCustomFilter, -1, v0->nMaxCustFilter * 4);
1190 wofn.lpstrCustomFilter = pw1;
1191 wofn.nMaxCustFilter = v0->nMaxCustFilter * 4;
1192 wofn.nFilterIndex = v0->nFilterIndex;
1193 pw2 = DuplicateMtoWMultiStringBuffer(v0->lpstrFile, v0->nMaxFile * 4);
1194 wofn.lpstrFile = pw2;
1195 wofn.nMaxFile = v0->nMaxFile * 4;
1196 pw3 = DuplicateMtoWBuffer(v0->lpstrFileTitle, -1, v0->nMaxFileTitle * 4);
1197 wofn.lpstrFileTitle = pw3;
1198 wofn.nMaxFileTitle = v0->nMaxFileTitle * 4;
1199 pw4 = DuplicateMtoW(v0->lpstrInitialDir, -1);
1200 wofn.lpstrInitialDir = pw4;
1201 pw5 = DuplicateMtoW(v0->lpstrTitle, -1);
1202 wofn.lpstrTitle = pw5;
1203 wofn.Flags = v0->Flags;
1204 wofn.nFileOffset = MtoW(NULL, 0, v0->lpstrFile, v0->nFileOffset);
1205 wofn.nFileExtension = MtoW(NULL, 0, v0->lpstrFile, v0->nFileExtension);
1206 pw6 = DuplicateMtoW(v0->lpstrDefExt, -1);
1207 wofn.lpstrDefExt = pw6;
1208 wofn.lCustData = v0->lCustData;
1209 wofn.lpfnHook = v0->lpfnHook;
1210 wofn.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);
1211 wofn.pvReserved = v0->pvReserved;
1212 wofn.FlagsEx = v0->FlagsEx;
1213 r = GetOpenFileNameW(&wofn);
1214 WtoM(v0->lpstrFile, v0->nMaxFile, wofn.lpstrFile, -1);
1215 TerminateStringM(v0->lpstrFile, v0->nMaxFile);
1216 v0->nFileOffset = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileOffset);
1217 v0->nFileExtension = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileExtension);
1219 FreeDuplicatedString(pw0);
1220 FreeDuplicatedString(pw1);
1221 FreeDuplicatedString(pw2);
1222 FreeDuplicatedString(pw3);
1223 FreeDuplicatedString(pw4);
1224 FreeDuplicatedString(pw5);
1225 FreeDuplicatedString(pw6);
1229 BOOL GetSaveFileNameM(LPOPENFILENAMEA v0)
1232 wchar_t* pw0 = NULL;
1233 wchar_t* pw1 = NULL;
1234 wchar_t* pw2 = NULL;
1235 wchar_t* pw3 = NULL;
1236 wchar_t* pw4 = NULL;
1237 wchar_t* pw5 = NULL;
1238 wchar_t* pw6 = NULL;
1239 wchar_t* pw7 = NULL;
1240 wchar_t* pw8 = NULL;
1241 wchar_t* pw9 = NULL;
1244 wofn.lStructSize = sizeof(OPENFILENAMEW);
1245 wofn.hwndOwner = v0->hwndOwner;
1246 wofn.hInstance = v0->hInstance;
1247 pw0 = DuplicateMtoWMultiString(v0->lpstrFilter);
1248 wofn.lpstrFilter = pw0;
1249 pw1 = DuplicateMtoWBuffer(v0->lpstrCustomFilter, -1, v0->nMaxCustFilter * 4);
1250 wofn.lpstrCustomFilter = pw1;
1251 wofn.nMaxCustFilter = v0->nMaxCustFilter * 4;
1252 wofn.nFilterIndex = v0->nFilterIndex;
1253 pw2 = DuplicateMtoWMultiStringBuffer(v0->lpstrFile, v0->nMaxFile * 4);
1254 wofn.lpstrFile = pw2;
1255 wofn.nMaxFile = v0->nMaxFile * 4;
1256 pw3 = DuplicateMtoWBuffer(v0->lpstrFileTitle, -1, v0->nMaxFileTitle * 4);
1257 wofn.lpstrFileTitle = pw3;
1258 wofn.nMaxFileTitle = v0->nMaxFileTitle * 4;
1259 pw4 = DuplicateMtoW(v0->lpstrInitialDir, -1);
1260 wofn.lpstrInitialDir = pw4;
1261 pw5 = DuplicateMtoW(v0->lpstrTitle, -1);
1262 wofn.lpstrTitle = pw5;
1263 wofn.Flags = v0->Flags;
1264 wofn.nFileOffset = MtoW(NULL, 0, v0->lpstrFile, v0->nFileOffset);
1265 wofn.nFileExtension = MtoW(NULL, 0, v0->lpstrFile, v0->nFileExtension);
1266 pw6 = DuplicateMtoW(v0->lpstrDefExt, -1);
1267 wofn.lpstrDefExt = pw6;
1268 wofn.lCustData = v0->lCustData;
1269 wofn.lpfnHook = v0->lpfnHook;
1270 wofn.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);
1271 wofn.pvReserved = v0->pvReserved;
1272 wofn.FlagsEx = v0->FlagsEx;
1273 r = GetSaveFileNameW(&wofn);
1274 WtoM(v0->lpstrFile, v0->nMaxFile, wofn.lpstrFile, -1);
1275 TerminateStringM(v0->lpstrFile, v0->nMaxFile);
1276 v0->nFileOffset = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileOffset);
1277 v0->nFileExtension = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileExtension);
1279 FreeDuplicatedString(pw0);
1280 FreeDuplicatedString(pw1);
1281 FreeDuplicatedString(pw2);
1282 FreeDuplicatedString(pw3);
1283 FreeDuplicatedString(pw4);
1284 FreeDuplicatedString(pw5);
1285 FreeDuplicatedString(pw6);
1289 HWND HtmlHelpM(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData)
1292 wchar_t* pw0 = NULL;
1294 pw0 = DuplicateMtoW(pszFile, -1);
1295 r = HtmlHelpW(hwndCaller, pw0, uCommand, dwData);
1297 FreeDuplicatedString(pw0);
1301 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)
1304 wchar_t* pw0 = NULL;
1305 wchar_t* pw1 = NULL;
1306 wchar_t* pw2 = NULL;
1307 wchar_t* pw3 = NULL;
1308 wchar_t* pw4 = NULL;
1309 wchar_t* pw5 = NULL;
1310 STARTUPINFOW wStartupInfo;
1312 pw0 = DuplicateMtoW(lpApplicationName, -1);
1313 pw1 = DuplicateMtoWBuffer(lpCommandLine, -1, (strlen(lpCommandLine) + 1) * 4);
1314 pw2 = DuplicateMtoW(lpCurrentDirectory, -1);
1315 wStartupInfo.cb = sizeof(LPSTARTUPINFOW);
1316 pw3 = DuplicateMtoW(lpStartupInfo->lpReserved, -1);
1317 wStartupInfo.lpReserved = pw3;
1318 pw4 = DuplicateMtoW(lpStartupInfo->lpDesktop, -1);
1319 wStartupInfo.lpDesktop = pw4;
1320 pw5 = DuplicateMtoW(lpStartupInfo->lpTitle, -1);
1321 wStartupInfo.lpTitle = pw5;
1322 wStartupInfo.dwX = lpStartupInfo->dwX;
1323 wStartupInfo.dwY = lpStartupInfo->dwY;
1324 wStartupInfo.dwXSize = lpStartupInfo->dwXSize;
1325 wStartupInfo.dwYSize = lpStartupInfo->dwYSize;
1326 wStartupInfo.dwXCountChars = lpStartupInfo->dwXCountChars;
1327 wStartupInfo.dwYCountChars = lpStartupInfo->dwYCountChars;
1328 wStartupInfo.dwFillAttribute = lpStartupInfo->dwFillAttribute;
1329 wStartupInfo.dwFlags = lpStartupInfo->dwFlags;
1330 wStartupInfo.wShowWindow = lpStartupInfo->wShowWindow;
1331 wStartupInfo.cbReserved2 = lpStartupInfo->cbReserved2;
1332 wStartupInfo.lpReserved2 = lpStartupInfo->lpReserved2;
1333 wStartupInfo.hStdInput = lpStartupInfo->hStdInput;
1334 wStartupInfo.hStdOutput = lpStartupInfo->hStdOutput;
1335 wStartupInfo.hStdError = lpStartupInfo->hStdError;
1336 r = CreateProcessW(pw0, pw1, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, pw2, &wStartupInfo, lpProcessInformation);
1337 WtoM(lpCommandLine, strlen(lpCommandLine) + 1, pw1, -1);
1339 FreeDuplicatedString(pw0);
1340 FreeDuplicatedString(pw1);
1341 FreeDuplicatedString(pw2);
1342 FreeDuplicatedString(pw3);
1343 FreeDuplicatedString(pw4);
1344 FreeDuplicatedString(pw5);
1348 HINSTANCE FindExecutableM(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
1351 wchar_t* pw0 = NULL;
1352 wchar_t* pw1 = NULL;
1353 wchar_t* pw2 = NULL;
1354 wchar_t* pw3 = NULL;
1356 pw0 = DuplicateMtoW(lpFile, -1);
1357 pw1 = DuplicateMtoW(lpDirectory, -1);
1358 pw2 = AllocateStringW(MAX_PATH * 4);
1359 r = FindExecutableW(pw0, pw1, pw2);
1360 // バッファ長不明のためオーバーランの可能性あり
1361 WtoM(lpResult, MAX_PATH, pw2, -1);
1362 TerminateStringM(lpResult, MAX_PATH);
1364 FreeDuplicatedString(pw0);
1365 FreeDuplicatedString(pw1);
1366 FreeDuplicatedString(pw2);
1367 FreeDuplicatedString(pw3);
1371 HINSTANCE ShellExecuteM(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd)
1374 wchar_t* pw0 = NULL;
1375 wchar_t* pw1 = NULL;
1376 wchar_t* pw2 = NULL;
1377 wchar_t* pw3 = NULL;
1379 pw0 = DuplicateMtoW(lpOperation, -1);
1380 pw1 = DuplicateMtoW(lpFile, -1);
1381 pw2 = DuplicateMtoW(lpParameters, -1);
1382 pw3 = DuplicateMtoW(lpDirectory, -1);
1383 r = ShellExecuteW(hwnd, pw0, pw1, pw2, pw3, nShowCmd);
1385 FreeDuplicatedString(pw0);
1386 FreeDuplicatedString(pw1);
1387 FreeDuplicatedString(pw2);
1388 FreeDuplicatedString(pw3);
1392 PIDLIST_ABSOLUTE SHBrowseForFolderM(LPBROWSEINFOA lpbi)
1394 PIDLIST_ABSOLUTE r = NULL;
1395 wchar_t* pw0 = NULL;
1396 wchar_t* pw1 = NULL;
1399 wbi.hwndOwner = lpbi->hwndOwner;
1400 wbi.pidlRoot = lpbi->pidlRoot;
1401 pw0 = DuplicateMtoWBuffer(lpbi->pszDisplayName, -1, MAX_PATH * 4);
1402 wbi.pszDisplayName = pw0;
1403 pw1 = DuplicateMtoW(lpbi->lpszTitle, -1);
1404 wbi.lpszTitle = pw1;
1405 wbi.ulFlags = lpbi->ulFlags;
1407 wbi.lpfn = lpbi->lpfn;
1408 wbi.lParam = lpbi->lParam;
1409 wbi.iImage = lpbi->iImage;
1410 r = SHBrowseForFolderW(&wbi);
1411 // バッファ長不明のためオーバーランの可能性あり
1412 WtoM(lpbi->pszDisplayName, MAX_PATH, wbi.pszDisplayName, -1);
1413 lpbi->iImage = wbi.iImage;
1415 FreeDuplicatedString(pw0);
1416 FreeDuplicatedString(pw1);
1420 BOOL SHGetPathFromIDListM(PCIDLIST_ABSOLUTE pidl, LPSTR pszPath)
1423 wchar_t* pw0 = NULL;
1425 pw0 = AllocateStringW(MAX_PATH * 4);
1426 r = SHGetPathFromIDListW(pidl, pw0);
1427 // バッファ長不明のためオーバーランの可能性あり
1428 WtoM(pszPath, MAX_PATH, pw0, -1);
1429 TerminateStringM(pszPath, MAX_PATH);
1431 FreeDuplicatedString(pw0);
1435 int SHFileOperationM(LPSHFILEOPSTRUCTA lpFileOp)
1438 wchar_t* pw0 = NULL;
1439 wchar_t* pw1 = NULL;
1440 wchar_t* pw2 = NULL;
1441 SHFILEOPSTRUCTW wFileOp;
1443 wFileOp.hwnd = lpFileOp->hwnd;
1444 wFileOp.wFunc = lpFileOp->wFunc;
1445 pw0 = DuplicateMtoWMultiString(lpFileOp->pFrom);
1446 wFileOp.pFrom = pw0;
1447 pw1 = DuplicateMtoWMultiString(lpFileOp->pTo);
1449 wFileOp.fFlags = lpFileOp->fFlags;
1450 wFileOp.fAnyOperationsAborted = lpFileOp->fAnyOperationsAborted;
1451 wFileOp.hNameMappings = lpFileOp->hNameMappings;
1452 pw2 = DuplicateMtoW(lpFileOp->lpszProgressTitle, -1);
1453 r = SHFileOperationW(&wFileOp);
1454 lpFileOp->fAnyOperationsAborted = wFileOp.fAnyOperationsAborted;
1456 FreeDuplicatedString(pw0);
1457 FreeDuplicatedString(pw1);
1458 FreeDuplicatedString(pw2);
1462 BOOL AppendMenuM(HMENU hMenu, UINT uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem)
1465 wchar_t* pw0 = NULL;
1467 if(uFlags & (MF_BITMAP | MF_OWNERDRAW))
1468 r = AppendMenuW(hMenu, uFlags, uIDNewItem, (LPCWSTR)lpNewItem);
1471 pw0 = DuplicateMtoW(lpNewItem, -1);
1472 r = AppendMenuW(hMenu, uFlags, uIDNewItem, pw0);
1475 FreeDuplicatedString(pw0);
1479 BOOL GetMenuItemInfoM(HMENU hmenu, UINT item, BOOL fByPosition, LPMENUITEMINFOA lpmii)
1482 wchar_t* pw0 = NULL;
1485 wmii.cbSize = sizeof(MENUITEMINFOW);
1486 wmii.fMask = lpmii->fMask;
1487 wmii.fType = lpmii->fType;
1488 wmii.fState = lpmii->fState;
1489 wmii.wID = lpmii->wID;
1490 wmii.hSubMenu = lpmii->hSubMenu;
1491 wmii.hbmpChecked = lpmii->hbmpChecked;
1492 wmii.hbmpUnchecked = lpmii->hbmpUnchecked;
1493 wmii.dwItemData = lpmii->dwItemData;
1494 pw0 = DuplicateMtoWBuffer(lpmii->dwTypeData, -1, lpmii->cch * 4);
1495 wmii.dwTypeData = pw0;
1496 wmii.cch = lpmii->cch * 4;
1497 r = GetMenuItemInfoW(hmenu, item, fByPosition, &wmii);
1498 lpmii->fType = wmii.fType;
1499 lpmii->fState = wmii.fState;
1500 lpmii->wID = wmii.wID;
1501 lpmii->hSubMenu = wmii.hSubMenu;
1502 lpmii->hbmpChecked = wmii.hbmpChecked;
1503 lpmii->hbmpUnchecked = wmii.hbmpUnchecked;
1504 lpmii->dwItemData = wmii.dwItemData;
1505 WtoM(lpmii->dwTypeData, lpmii->cch, wmii.dwTypeData, -1);
1506 TerminateStringM(lpmii->dwTypeData, lpmii->cch);
1508 FreeDuplicatedString(pw0);
1512 HFONT CreateFontIndirectM(CONST LOGFONTA *lplf)
1517 wlf.lfHeight = lplf->lfHeight;
1518 wlf.lfWidth = lplf->lfWidth;
1519 wlf.lfEscapement = lplf->lfEscapement;
1520 wlf.lfOrientation = lplf->lfOrientation;
1521 wlf.lfWeight = lplf->lfWeight;
1522 wlf.lfItalic = lplf->lfItalic;
1523 wlf.lfUnderline = lplf->lfUnderline;
1524 wlf.lfStrikeOut = lplf->lfStrikeOut;
1525 wlf.lfCharSet = lplf->lfCharSet;
1526 wlf.lfOutPrecision = lplf->lfOutPrecision;
1527 wlf.lfClipPrecision = lplf->lfClipPrecision;
1528 wlf.lfQuality = lplf->lfQuality;
1529 wlf.lfPitchAndFamily = lplf->lfPitchAndFamily;
1530 MtoW(wlf.lfFaceName, LF_FACESIZE, lplf->lfFaceName, -1);
1531 TerminateStringW(wlf.lfFaceName, LF_FACESIZE);
1532 r = CreateFontIndirect(&wlf);
1537 BOOL ChooseFontM(LPCHOOSEFONTA v0)
1540 wchar_t* pw0 = NULL;
1544 a0.lStructSize = sizeof(CHOOSEFONTW);
1545 a0.hwndOwner = v0->hwndOwner;
1547 if(v0->lpLogFont && (pwlf = (LOGFONTW*)malloc(sizeof(LOGFONTW))))
1549 pwlf->lfHeight = v0->lpLogFont->lfHeight;
1550 pwlf->lfWidth = v0->lpLogFont->lfWidth;
1551 pwlf->lfEscapement = v0->lpLogFont->lfEscapement;
1552 pwlf->lfOrientation = v0->lpLogFont->lfOrientation;
1553 pwlf->lfWeight = v0->lpLogFont->lfWeight;
1554 pwlf->lfItalic = v0->lpLogFont->lfItalic;
1555 pwlf->lfUnderline = v0->lpLogFont->lfUnderline;
1556 pwlf->lfStrikeOut = v0->lpLogFont->lfStrikeOut;
1557 pwlf->lfCharSet = v0->lpLogFont->lfCharSet;
1558 pwlf->lfOutPrecision = v0->lpLogFont->lfOutPrecision;
1559 pwlf->lfClipPrecision = v0->lpLogFont->lfClipPrecision;
1560 pwlf->lfQuality = v0->lpLogFont->lfQuality;
1561 pwlf->lfPitchAndFamily = v0->lpLogFont->lfPitchAndFamily;
1562 MtoW(pwlf->lfFaceName, LF_FACESIZE, v0->lpLogFont->lfFaceName, -1);
1563 TerminateStringW(pwlf->lfFaceName, LF_FACESIZE);
1567 a0.lpLogFont = pwlf;
1568 a0.iPointSize = v0->iPointSize;
1569 a0.Flags = v0->Flags;
1570 a0.rgbColors = v0->rgbColors;
1571 a0.lCustData = v0->lCustData;
1572 a0.lpfnHook = v0->lpfnHook;
1573 a0.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);
1574 a0.hInstance = v0->hInstance;
1575 a0.lpszStyle = DuplicateMtoWBuffer(v0->lpszStyle, -1, LF_FACESIZE * 4);
1576 a0.nFontType = v0->nFontType;
1577 a0.nSizeMin = v0->nSizeMin;
1578 a0.nSizeMax = v0->nSizeMax;
1579 r = ChooseFontW(&a0);
1582 v0->lpLogFont->lfHeight = pwlf->lfHeight;
1583 v0->lpLogFont->lfWidth = pwlf->lfWidth;
1584 v0->lpLogFont->lfEscapement = pwlf->lfEscapement;
1585 v0->lpLogFont->lfOrientation = pwlf->lfOrientation;
1586 v0->lpLogFont->lfWeight = pwlf->lfWeight;
1587 v0->lpLogFont->lfItalic = pwlf->lfItalic;
1588 v0->lpLogFont->lfUnderline = pwlf->lfUnderline;
1589 v0->lpLogFont->lfStrikeOut = pwlf->lfStrikeOut;
1590 v0->lpLogFont->lfCharSet = pwlf->lfCharSet;
1591 v0->lpLogFont->lfOutPrecision = pwlf->lfOutPrecision;
1592 v0->lpLogFont->lfClipPrecision = pwlf->lfClipPrecision;
1593 v0->lpLogFont->lfQuality = pwlf->lfQuality;
1594 v0->lpLogFont->lfPitchAndFamily = pwlf->lfPitchAndFamily;
1595 WtoM(v0->lpLogFont->lfFaceName, LF_FACESIZE, pwlf->lfFaceName, -1);
1596 TerminateStringM(v0->lpLogFont->lfFaceName, LF_FACESIZE);
1598 v0->rgbColors = a0.rgbColors;
1599 WtoM(v0->lpszStyle, LF_FACESIZE, a0.lpszStyle, -1);
1600 TerminateStringM(v0->lpszStyle, LF_FACESIZE);
1601 v0->nFontType = a0.nFontType;
1604 FreeDuplicatedString(a0.lpTemplateName);
1605 FreeDuplicatedString(a0.lpszStyle);
1607 FreeDuplicatedString(pw0);
1611 INT_PTR DialogBoxParamM(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
1614 wchar_t* pw0 = NULL;
1616 pw0 = DuplicateMtoW(lpTemplateName, -1);
1617 r = DialogBoxParamW(hInstance, pw0, hWndParent, lpDialogFunc, dwInitParam);
1619 FreeDuplicatedString(pw0);
1623 HWND CreateDialogParamM(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
1626 wchar_t* pw0 = NULL;
1628 pw0 = DuplicateMtoW(lpTemplateName, -1);
1629 r = CreateDialogParamW(hInstance, pw0, hWndParent, lpDialogFunc, dwInitParam);
1631 FreeDuplicatedString(pw0);
1635 int mkdirM(const char * _Path)
1638 wchar_t* pw0 = NULL;
1640 pw0 = DuplicateMtoW(_Path, -1);
1643 FreeDuplicatedString(pw0);
1647 int _mkdirM(const char * _Path)
1650 wchar_t* pw0 = NULL;
1652 pw0 = DuplicateMtoW(_Path, -1);
1655 FreeDuplicatedString(pw0);
1659 int rmdirM(const char * _Path)
1662 wchar_t* pw0 = NULL;
1664 pw0 = DuplicateMtoW(_Path, -1);
1667 FreeDuplicatedString(pw0);
1671 int _rmdirM(const char * _Path)
1674 wchar_t* pw0 = NULL;
1676 pw0 = DuplicateMtoW(_Path, -1);
1679 FreeDuplicatedString(pw0);
1683 size_t _mbslenM(const unsigned char * _Str)
1686 wchar_t* pw0 = NULL;
1688 pw0 = DuplicateMtoW(_Str, -1);
1691 FreeDuplicatedString(pw0);
1695 unsigned char * _mbschrM(const unsigned char * _Str, unsigned int _Ch)
1697 unsigned char* r = NULL;
1698 wchar_t* pw0 = NULL;
1701 pw0 = DuplicateMtoW(_Str, -1);
1702 // TODO: 非ASCII文字の対応
1703 wr = wcschr(pw0, _Ch);
1707 r = _Str + WtoM(NULL, 0, pw0, -1) - 1;
1710 FreeDuplicatedString(pw0);
1714 unsigned char * _mbsrchrM(const unsigned char * _Str, unsigned int _Ch)
1716 unsigned char* r = NULL;
1717 wchar_t* pw0 = NULL;
1720 pw0 = DuplicateMtoW(_Str, -1);
1721 // TODO: 非ASCII文字の対応
1722 wr = wcsrchr(pw0, _Ch);
1726 r = _Str + WtoM(NULL, 0, pw0, -1) - 1;
1729 FreeDuplicatedString(pw0);
1733 unsigned char * _mbsstrM(const unsigned char * _Str, const unsigned char * _Substr)
1735 unsigned char* r = NULL;
1736 wchar_t* pw0 = NULL;
1737 wchar_t* pw1 = NULL;
1740 pw0 = DuplicateMtoW(_Str, -1);
1741 pw1 = DuplicateMtoW(_Substr, -1);
1742 wr = wcsstr(pw0, pw1);
1746 r = _Str + WtoM(NULL, 0, pw0, -1) - 1;
1749 FreeDuplicatedString(pw0);
1750 FreeDuplicatedString(pw1);
1754 int _mbscmpM(const unsigned char * _Str1, const unsigned char * _Str2)
1757 wchar_t* pw0 = NULL;
1758 wchar_t* pw1 = NULL;
1760 pw0 = DuplicateMtoW(_Str1, -1);
1761 pw1 = DuplicateMtoW(_Str2, -1);
1762 r = wcscmp(pw0, pw1);
1764 FreeDuplicatedString(pw0);
1765 FreeDuplicatedString(pw1);
1769 int _mbsicmpM(const unsigned char * _Str1, const unsigned char * _Str2)
1772 wchar_t* pw0 = NULL;
1773 wchar_t* pw1 = NULL;
1775 pw0 = DuplicateMtoW(_Str1, -1);
1776 pw1 = DuplicateMtoW(_Str2, -1);
1777 r = _wcsicmp(pw0, pw1);
1779 FreeDuplicatedString(pw0);
1780 FreeDuplicatedString(pw1);
1784 int _mbsncmpM(const unsigned char * _Str1, const unsigned char * _Str2, size_t _MaxCount)
1787 wchar_t* pw0 = NULL;
1788 wchar_t* pw1 = NULL;
1790 pw0 = DuplicateMtoW(_Str1, -1);
1791 pw1 = DuplicateMtoW(_Str2, -1);
1792 r = wcsncmp(pw0, pw1, _MaxCount);
1794 FreeDuplicatedString(pw0);
1795 FreeDuplicatedString(pw1);
1799 unsigned char * _mbslwrM(unsigned char * _String)
1801 unsigned char* r = NULL;
1802 wchar_t* pw0 = NULL;
1804 pw0 = DuplicateMtoW(_String, -1);
1807 WtoM(_String, strlen(_String) + 1, pw0, -1);
1809 FreeDuplicatedString(pw0);
1813 unsigned char * _mbsuprM(unsigned char * _String)
1815 unsigned char* r = NULL;
1816 wchar_t* pw0 = NULL;
1818 pw0 = DuplicateMtoW(_String, -1);
1821 WtoM(_String, strlen(_String) + 1, pw0, -1);
1823 FreeDuplicatedString(pw0);
1827 unsigned char * _mbsnincM(const unsigned char * _Str, size_t _Count)
1829 unsigned char* r = NULL;
1830 wchar_t* pw0 = NULL;
1833 pw0 = DuplicateMtoW(_Str, -1);
1834 wr = _wcsninc(pw0, _Count);
1838 r = _Str + WtoM(NULL, 0, pw0, -1) - 1;
1841 FreeDuplicatedString(pw0);
1845 FILE * fopenM(const char * _Filename, const char * _Mode)
1848 wchar_t* pw0 = NULL;
1849 wchar_t* pw1 = NULL;
1851 pw0 = DuplicateMtoW(_Filename, -1);
1852 pw1 = DuplicateMtoW(_Mode, -1);
1853 r = _wfopen(pw0, pw1);
1855 FreeDuplicatedString(pw0);
1856 FreeDuplicatedString(pw1);