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 HANDLE CreateFileM(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
360 HANDLE r = INVALID_HANDLE_VALUE;
363 pw0 = DuplicateMtoW(lpFileName, -1);
364 r = CreateFileW(pw0, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
366 FreeDuplicatedString(pw0);
370 int MessageBoxM(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
376 pw0 = DuplicateMtoW(lpText, -1);
377 pw1 = DuplicateMtoW(lpCaption, -1);
378 r = MessageBoxW(hWnd, pw0, pw1, uType);
380 FreeDuplicatedString(pw0);
381 FreeDuplicatedString(pw1);
385 HANDLE FindFirstFileM(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
387 HANDLE r = INVALID_HANDLE_VALUE;
391 pw0 = DuplicateMtoW(lpFileName, -1);
392 r = FindFirstFileW(pw0, &a0);
393 if(r != INVALID_HANDLE_VALUE)
395 lpFindFileData->dwFileAttributes = a0.dwFileAttributes;
396 lpFindFileData->ftCreationTime = a0.ftCreationTime;
397 lpFindFileData->ftLastAccessTime = a0.ftLastAccessTime;
398 lpFindFileData->ftLastWriteTime = a0.ftLastWriteTime;
399 lpFindFileData->nFileSizeHigh = a0.nFileSizeHigh;
400 lpFindFileData->nFileSizeLow = a0.nFileSizeLow;
401 lpFindFileData->dwReserved0 = a0.dwReserved0;
402 lpFindFileData->dwReserved1 = a0.dwReserved1;
403 WtoM(lpFindFileData->cFileName, sizeof(lpFindFileData->cFileName), a0.cFileName, -1);
404 WtoM(lpFindFileData->cAlternateFileName, sizeof(lpFindFileData->cAlternateFileName), a0.cAlternateFileName, -1);
407 FreeDuplicatedString(pw0);
411 BOOL FindNextFileM(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData)
416 r = FindNextFileW(hFindFile, &a0);
419 lpFindFileData->dwFileAttributes = a0.dwFileAttributes;
420 lpFindFileData->ftCreationTime = a0.ftCreationTime;
421 lpFindFileData->ftLastAccessTime = a0.ftLastAccessTime;
422 lpFindFileData->ftLastWriteTime = a0.ftLastWriteTime;
423 lpFindFileData->nFileSizeHigh = a0.nFileSizeHigh;
424 lpFindFileData->nFileSizeLow = a0.nFileSizeLow;
425 lpFindFileData->dwReserved0 = a0.dwReserved0;
426 lpFindFileData->dwReserved1 = a0.dwReserved1;
427 WtoM(lpFindFileData->cFileName, sizeof(lpFindFileData->cFileName), a0.cFileName, -1);
428 WtoM(lpFindFileData->cAlternateFileName, sizeof(lpFindFileData->cAlternateFileName), a0.cAlternateFileName, -1);
434 DWORD GetLogicalDriveStringsM(DWORD nBufferLength, LPSTR lpBuffer)
439 pw0 = AllocateStringW(nBufferLength * 4);
440 GetLogicalDriveStringsW(nBufferLength * 4, pw0);
441 WtoMMultiString(lpBuffer, nBufferLength, pw0);
442 r = TerminateStringM(lpBuffer, nBufferLength);
444 FreeDuplicatedString(pw0);
448 ATOM RegisterClassExM(CONST WNDCLASSEXA * v0)
452 // WNDPROCがShift_JIS用であるため
453 r = RegisterClassExA(v0);
458 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)
464 pw0 = DuplicateMtoW(lpClassName, -1);
465 pw1 = DuplicateMtoW(lpWindowName, -1);
466 r = CreateWindowExW(dwExStyle, pw0, pw1, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
468 FreeDuplicatedString(pw0);
469 FreeDuplicatedString(pw1);
473 LONG GetWindowLongM(HWND hWnd, int nIndex)
477 // WNDPROCがShift_JIS用であるため
478 if(IsWindowUnicode(hWnd))
479 r = GetWindowLongW(hWnd, nIndex);
481 r = GetWindowLongA(hWnd, nIndex);
486 LONG SetWindowLongM(HWND hWnd, int nIndex, LONG dwNewLong)
490 // WNDPROCがShift_JIS用であるため
491 if(IsWindowUnicode(hWnd))
492 r = SetWindowLongW(hWnd, nIndex, dwNewLong);
494 r = SetWindowLongA(hWnd, nIndex, dwNewLong);
499 LRESULT DefWindowProcM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
503 // WNDPROCがShift_JIS用であるため
504 if(IsWindowUnicode(hWnd))
505 r = DefWindowProcW(hWnd, Msg, wParam, lParam);
507 r = DefWindowProcA(hWnd, Msg, wParam, lParam);
512 LRESULT CallWindowProcM(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
516 // WNDPROCがShift_JIS用であるため
517 if(IsWindowUnicode(hWnd))
518 r = CallWindowProcW(lpPrevWndFunc, hWnd, Msg, wParam, lParam);
520 r = CallWindowProcA(lpPrevWndFunc, hWnd, Msg, wParam, lParam);
525 LRESULT SendMessageM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
533 LVFINDINFOA* pmLVFindInfo;
534 LVFINDINFOW wLVFindInfo;
535 LVCOLUMNA* pmLVColumn;
537 wchar_t ClassName[MAX_PATH];
542 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
543 r = SendMessageW(hWnd, WM_SETTEXT, wParam, (LPARAM)pw0);
546 pw0 = AllocateStringW(wParam * 4);
547 SendMessageW(hWnd, WM_GETTEXT, wParam * 4, (LPARAM)pw0);
548 WtoM((LPSTR)lParam, wParam, pw0, -1);
549 r = TerminateStringM((LPSTR)lParam, wParam);
551 case WM_GETTEXTLENGTH:
552 Size = SendMessageW(hWnd, WM_GETTEXTLENGTH, wParam, lParam) + 1;
553 pw0 = AllocateStringW(Size);
554 SendMessageW(hWnd, WM_GETTEXT, (WPARAM)Size, (LPARAM)pw0);
555 r = WtoM(NULL, 0, pw0, -1) - 1;
558 GetClassNameW(hWnd, ClassName, sizeof(ClassName) / sizeof(wchar_t));
559 if(_wcsicmp(ClassName, WC_EDITW) == 0)
564 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
565 r = SendMessageW(hWnd, EM_REPLACESEL, wParam, (LPARAM)pw0);
568 r = SendMessageW(hWnd, Msg, wParam, lParam);
572 else if(_wcsicmp(ClassName, WC_COMBOBOXW) == 0)
577 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
578 r = SendMessageW(hWnd, CB_ADDSTRING, wParam, (LPARAM)pw0);
581 Size = SendMessageW(hWnd, CB_GETLBTEXTLEN, wParam, 0) + 1;
582 pw0 = AllocateStringW(Size);
583 SendMessageW(hWnd, CB_GETLBTEXT, wParam, (LPARAM)pw0);
584 // バッファ長不明のためオーバーランの可能性あり
585 WtoM((LPSTR)lParam, Size * 4, pw0, -1);
586 r = TerminateStringM((LPSTR)lParam, Size * 4);
588 case CB_GETLBTEXTLEN:
589 Size = SendMessageW(hWnd, CB_GETLBTEXTLEN, wParam, 0) + 1;
590 pw0 = AllocateStringW(Size);
591 SendMessageW(hWnd, WM_GETTEXT, wParam, (LPARAM)pw0);
592 r = WtoM(NULL, 0, pw0, -1) - 1;
594 case CB_INSERTSTRING:
595 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
596 r = SendMessageW(hWnd, CB_INSERTSTRING, wParam, (LPARAM)pw0);
598 case CB_FINDSTRINGEXACT:
599 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
600 r = SendMessageW(hWnd, CB_FINDSTRINGEXACT, wParam, (LPARAM)pw0);
603 r = SendMessageW(hWnd, Msg, wParam, lParam);
607 else if(_wcsicmp(ClassName, WC_LISTBOXW) == 0)
612 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
613 r = SendMessageW(hWnd, LB_ADDSTRING, wParam, (LPARAM)pw0);
615 case LB_INSERTSTRING:
616 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
617 r = SendMessageW(hWnd, LB_INSERTSTRING, wParam, (LPARAM)pw0);
620 Size = SendMessageW(hWnd, LB_GETTEXTLEN, wParam, 0) + 1;
621 pw0 = AllocateStringW(Size);
622 SendMessageW(hWnd, LB_GETTEXT, wParam, (LPARAM)pw0);
623 // バッファ長不明のためオーバーランの可能性あり
624 WtoM((LPSTR)lParam, Size * 4, pw0, -1);
625 r = TerminateStringM((LPSTR)lParam, Size * 4);
628 Size = SendMessageW(hWnd, LB_GETTEXTLEN, wParam, 0) + 1;
629 pw0 = AllocateStringW(Size);
630 SendMessageW(hWnd, WM_GETTEXT, wParam, (LPARAM)pw0);
631 r = WtoM(NULL, 0, pw0, -1) - 1;
634 r = SendMessageW(hWnd, Msg, wParam, lParam);
638 else if(_wcsicmp(ClassName, WC_LISTVIEWW) == 0)
643 pmLVItem = (LVITEMA*)lParam;
644 wLVItem.mask = pmLVItem->mask;
645 wLVItem.iItem = pmLVItem->iItem;
646 wLVItem.iSubItem = pmLVItem->iSubItem;
647 wLVItem.state = pmLVItem->state;
648 wLVItem.stateMask = pmLVItem->stateMask;
649 if(pmLVItem->mask & LVIF_TEXT)
651 Size = pmLVItem->cchTextMax * 4;
652 pw0 = AllocateStringW(Size);
653 wLVItem.pszText = pw0;
654 wLVItem.cchTextMax = Size;
656 wLVItem.iImage = pmLVItem->iImage;
657 wLVItem.lParam = pmLVItem->lParam;
658 wLVItem.iIndent = pmLVItem->iIndent;
659 r = SendMessageW(hWnd, LVM_GETITEMW, wParam, (LPARAM)&wLVItem);
660 pmLVItem->mask = wLVItem.mask;
661 pmLVItem->iItem = wLVItem.iItem;
662 pmLVItem->iSubItem = wLVItem.iSubItem;
663 pmLVItem->state = wLVItem.state;
664 pmLVItem->stateMask = wLVItem.stateMask;
665 if(pmLVItem->mask & LVIF_TEXT)
667 WtoM(pmLVItem->pszText, pmLVItem->cchTextMax, wLVItem.pszText, -1);
668 TerminateStringM(pmLVItem->pszText, pmLVItem->cchTextMax);
670 pmLVItem->iImage = wLVItem.iImage;
671 pmLVItem->lParam = wLVItem.lParam;
672 pmLVItem->iIndent = wLVItem.iIndent;
675 pmLVItem = (LVITEMA*)lParam;
676 wLVItem.mask = pmLVItem->mask;
677 wLVItem.iItem = pmLVItem->iItem;
678 wLVItem.iSubItem = pmLVItem->iSubItem;
679 wLVItem.state = pmLVItem->state;
680 wLVItem.stateMask = pmLVItem->stateMask;
681 if(pmLVItem->mask & LVIF_TEXT)
683 pw0 = DuplicateMtoW(pmLVItem->pszText, -1);
684 wLVItem.pszText = pw0;
685 // TODO: cchTextMaxの確認
686 wLVItem.cchTextMax = pmLVItem->cchTextMax;
688 wLVItem.iImage = pmLVItem->iImage;
689 wLVItem.lParam = pmLVItem->lParam;
690 wLVItem.iIndent = pmLVItem->iIndent;
691 r = SendMessageW(hWnd, LVM_SETITEMW, wParam, (LPARAM)&wLVItem);
693 case LVM_INSERTITEMA:
694 pmLVItem = (LVITEMA*)lParam;
695 wLVItem.mask = pmLVItem->mask;
696 wLVItem.iItem = pmLVItem->iItem;
697 wLVItem.iSubItem = pmLVItem->iSubItem;
698 wLVItem.state = pmLVItem->state;
699 wLVItem.stateMask = pmLVItem->stateMask;
700 if(pmLVItem->mask & LVIF_TEXT)
702 pw0 = DuplicateMtoW(pmLVItem->pszText, -1);
703 wLVItem.pszText = pw0;
704 // TODO: cchTextMaxの確認
705 wLVItem.cchTextMax = pmLVItem->cchTextMax;
707 wLVItem.iImage = pmLVItem->iImage;
708 wLVItem.lParam = pmLVItem->lParam;
709 wLVItem.iIndent = pmLVItem->iIndent;
710 r = SendMessageW(hWnd, LVM_INSERTITEMW, wParam, (LPARAM)&wLVItem);
713 pmLVFindInfo = (LVFINDINFOA*)lParam;
714 wLVFindInfo.flags = pmLVFindInfo->flags;
715 if(pmLVFindInfo->flags & (LVFI_STRING | LVFI_PARTIAL))
717 pw0 = DuplicateMtoW(pmLVFindInfo->psz, -1);
718 wLVFindInfo.psz = pw0;
720 wLVFindInfo.lParam = pmLVFindInfo->lParam;
721 wLVFindInfo.pt = pmLVFindInfo->pt;
722 wLVFindInfo.vkDirection = pmLVFindInfo->vkDirection;
723 r = SendMessageW(hWnd, LVM_FINDITEMW, wParam, (LPARAM)&wLVItem);
726 pmLVColumn = (LVCOLUMNA*)lParam;
727 wLVColumn.mask = pmLVColumn->mask;
728 wLVColumn.fmt = pmLVColumn->fmt;
729 wLVColumn.cx = pmLVColumn->cx;
730 Size = pmLVColumn->cchTextMax * 4;
731 if(pmLVColumn->mask & LVCF_TEXT)
733 pw0 = AllocateStringW(Size);
734 wLVColumn.pszText = pw0;
735 wLVColumn.cchTextMax = Size;
737 wLVColumn.iSubItem = pmLVColumn->iSubItem;
738 wLVColumn.iImage = pmLVColumn->iImage;
739 wLVColumn.iOrder = pmLVColumn->iOrder;
740 r = SendMessageW(hWnd, LVM_GETCOLUMNW, wParam, (LPARAM)&wLVColumn);
741 pmLVColumn->mask = wLVColumn.mask;
742 pmLVColumn->fmt = wLVColumn.fmt;
743 pmLVColumn->cx = wLVColumn.cx;
744 if(pmLVColumn->mask & LVCF_TEXT)
746 WtoM(pmLVColumn->pszText, pmLVColumn->cchTextMax, wLVColumn.pszText, -1);
747 TerminateStringM(pmLVColumn->pszText, pmLVColumn->cchTextMax);
749 pmLVColumn->iSubItem = wLVColumn.iSubItem;
750 pmLVColumn->iImage = wLVColumn.iImage;
751 pmLVColumn->iOrder = wLVColumn.iOrder;
753 case LVM_INSERTCOLUMNA:
754 pmLVColumn = (LVCOLUMNA*)lParam;
755 wLVColumn.mask = pmLVColumn->mask;
756 wLVColumn.fmt = pmLVColumn->fmt;
757 wLVColumn.cx = pmLVColumn->cx;
758 if(pmLVColumn->mask & LVCF_TEXT)
760 pw0 = DuplicateMtoW(pmLVColumn->pszText, -1);
761 wLVColumn.pszText = pw0;
762 // TODO: cchTextMaxの確認
763 wLVColumn.cchTextMax = pmLVColumn->cchTextMax;
765 wLVColumn.iSubItem = pmLVColumn->iSubItem;
766 wLVColumn.iImage = pmLVColumn->iImage;
767 wLVColumn.iOrder = pmLVColumn->iOrder;
768 r = SendMessageW(hWnd, LVM_INSERTCOLUMNW, wParam, (LPARAM)&wLVColumn);
770 case LVM_GETITEMTEXTA:
771 pmLVItem = (LVITEMA*)lParam;
772 wLVItem.mask = pmLVItem->mask;
773 wLVItem.iItem = pmLVItem->iItem;
774 wLVItem.iSubItem = pmLVItem->iSubItem;
775 wLVItem.state = pmLVItem->state;
776 wLVItem.stateMask = pmLVItem->stateMask;
777 Size = pmLVItem->cchTextMax * 4;
778 pw0 = AllocateStringW(Size);
779 wLVItem.pszText = pw0;
780 wLVItem.cchTextMax = Size;
781 wLVItem.iImage = pmLVItem->iImage;
782 wLVItem.lParam = pmLVItem->lParam;
783 wLVItem.iIndent = pmLVItem->iIndent;
784 r = SendMessageW(hWnd, LVM_GETITEMTEXTW, wParam, (LPARAM)&wLVItem);
785 pmLVItem->mask = wLVItem.mask;
786 pmLVItem->iItem = wLVItem.iItem;
787 pmLVItem->iSubItem = wLVItem.iSubItem;
788 pmLVItem->state = wLVItem.state;
789 pmLVItem->stateMask = wLVItem.stateMask;
790 WtoM(pmLVItem->pszText, pmLVItem->cchTextMax, wLVItem.pszText, -1);
791 TerminateStringM(pmLVItem->pszText, pmLVItem->cchTextMax);
792 pmLVItem->iImage = wLVItem.iImage;
793 pmLVItem->lParam = wLVItem.lParam;
794 pmLVItem->iIndent = wLVItem.iIndent;
797 r = SendMessageW(hWnd, Msg, wParam, lParam);
801 else if(_wcsicmp(ClassName, STATUSCLASSNAMEW) == 0)
806 pw0 = DuplicateMtoW((LPCSTR)lParam, -1);
807 r = SendMessageW(hWnd, SB_SETTEXTW, wParam, (LPARAM)pw0);
810 r = SendMessageW(hWnd, Msg, wParam, lParam);
815 r = SendMessageW(hWnd, Msg, wParam, lParam);
819 FreeDuplicatedString(pw0);
820 FreeDuplicatedString(pw1);
824 LRESULT DefDlgProcM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
828 // WNDPROCがShift_JIS用であるため
829 if(IsWindowUnicode(hWnd))
830 r = DefDlgProcW(hWnd, Msg, wParam, lParam);
832 r = DefDlgProcA(hWnd, Msg, wParam, lParam);
837 LRESULT SendDlgItemMessageM(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam)
841 r = SendMessageM(GetDlgItem(hDlg, nIDDlgItem), Msg, wParam, lParam);
846 BOOL SetWindowTextM(HWND hWnd, LPCSTR lpString)
851 pw0 = DuplicateMtoW(lpString, -1);
852 r = SetWindowTextW(hWnd, pw0);
854 FreeDuplicatedString(pw0);
858 UINT DragQueryFileM(HDROP hDrop, UINT iFile, LPSTR lpszFile, UINT cch)
863 if(iFile == (UINT)-1)
864 r = DragQueryFileW(hDrop, iFile, (LPWSTR)lpszFile, cch);
867 pw0 = AllocateStringW(cch * 4);
868 DragQueryFileW(hDrop, iFile, pw0, cch * 4);
869 WtoM(lpszFile, cch, pw0, -1);
870 r = TerminateStringM(lpszFile, cch);
873 FreeDuplicatedString(pw0);
877 DWORD GetCurrentDirectoryM(DWORD nBufferLength, LPSTR lpBuffer)
882 pw0 = AllocateStringW(nBufferLength * 4);
883 GetCurrentDirectoryW(nBufferLength * 4, pw0);
884 WtoM(lpBuffer, nBufferLength, pw0, -1);
885 r = TerminateStringM(lpBuffer, nBufferLength);
887 FreeDuplicatedString(pw0);
891 BOOL SetCurrentDirectoryM(LPCSTR lpPathName)
896 pw0 = DuplicateMtoW(lpPathName, -1);
897 r = SetCurrentDirectoryW(pw0);
899 FreeDuplicatedString(pw0);
903 BOOL SetDllDirectoryM(LPCSTR lpPathName)
908 pw0 = DuplicateMtoW(lpPathName, -1);
909 r = SetDllDirectoryW(pw0);
911 FreeDuplicatedString(pw0);
915 DWORD GetTempPathM(DWORD nBufferLength, LPSTR lpBuffer)
920 pw0 = AllocateStringW(nBufferLength * 4);
921 GetTempPathW(nBufferLength * 4, pw0);
922 WtoM(lpBuffer, nBufferLength, pw0, -1);
923 r = TerminateStringM(lpBuffer, nBufferLength);
925 FreeDuplicatedString(pw0);
929 DWORD GetFileAttributesM(LPCSTR lpFileName)
934 pw0 = DuplicateMtoW(lpFileName, -1);
935 r = GetFileAttributesW(pw0);
937 FreeDuplicatedString(pw0);
941 DWORD GetModuleFileNameM(HMODULE hModule, LPCH lpFilename, DWORD nSize)
946 pw0 = AllocateStringW(nSize * 4);
947 GetModuleFileNameW(hModule, pw0, nSize * 4);
948 WtoM(lpFilename, nSize, pw0, -1);
949 r = TerminateStringM(lpFilename, nSize);
951 FreeDuplicatedString(pw0);
955 LSTATUS RegOpenKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
960 pw0 = DuplicateMtoW(lpSubKey, -1);
961 r = RegOpenKeyExW(hKey, pw0, ulOptions, samDesired, phkResult);
963 FreeDuplicatedString(pw0);
967 LSTATUS RegCreateKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass, DWORD dwOptions, REGSAM samDesired, CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition)
973 pw0 = DuplicateMtoW(lpSubKey, -1);
974 pw1 = DuplicateMtoW(lpClass, -1);
975 r = RegCreateKeyExW(hKey, pw0, Reserved, pw1, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition);
977 FreeDuplicatedString(pw0);
978 FreeDuplicatedString(pw1);
982 LSTATUS RegDeleteValueM(HKEY hKey, LPCSTR lpValueName)
987 pw0 = DuplicateMtoW(lpValueName, -1);
988 r = RegDeleteValueW(hKey, pw0);
990 FreeDuplicatedString(pw0);
994 LSTATUS RegQueryValueExM(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)
1002 pw0 = DuplicateMtoW(lpValueName, -1);
1003 if(RegQueryValueExW(hKey, pw0, NULL, &dwType, NULL, 0) == ERROR_SUCCESS)
1012 pw1 = AllocateStringW(*lpcbData / sizeof(char) * 4);
1013 wcbData = *lpcbData / sizeof(char) * 4;
1014 r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, (LPBYTE)pw1, &wcbData);
1016 *lpcbData = sizeof(char) * WtoM((char*)lpData, *lpcbData / sizeof(char), pw1, wcbData / sizeof(wchar_t));
1018 *lpcbData = sizeof(char) * WtoM(NULL, 0, pw1, wcbData / sizeof(wchar_t));
1022 r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, lpData, lpcbData);
1027 r = RegQueryValueExW(hKey, pw0, lpReserved, lpType, lpData, lpcbData);
1029 FreeDuplicatedString(pw0);
1030 FreeDuplicatedString(pw1);
1034 LSTATUS RegSetValueExM(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE* lpData, DWORD cbData)
1037 wchar_t* pw0 = NULL;
1038 wchar_t* pw1 = NULL;
1041 pw0 = DuplicateMtoW(lpValueName, -1);
1047 wcbData = MtoW(NULL, 0, (char*)lpData, cbData / sizeof(char));
1048 pw1 = AllocateStringW(wcbData);
1049 MtoW(pw1, wcbData, (char*)lpData, cbData / sizeof(char));
1050 wcbData = sizeof(wchar_t) * wcbData;
1051 lpData = (BYTE*)pw1;
1055 r = RegSetValueExW(hKey, pw0, Reserved, dwType, lpData, cbData);
1057 FreeDuplicatedString(pw0);
1058 FreeDuplicatedString(pw1);
1062 BOOL TextOutM(HDC hdc, int x, int y, LPCSTR lpString, int c)
1065 wchar_t* pw0 = NULL;
1067 pw0 = DuplicateMtoW(lpString, c);
1068 r = TextOutW(hdc, x, y, pw0, wcslen(pw0));
1070 FreeDuplicatedString(pw0);
1074 BOOL GetTextExtentPoint32M(HDC hdc, LPCSTR lpString, int c, LPSIZE psizl)
1077 wchar_t* pw0 = NULL;
1079 pw0 = DuplicateMtoW(lpString, c);
1080 r = GetTextExtentPoint32W(hdc, pw0, wcslen(pw0), psizl);
1082 FreeDuplicatedString(pw0);
1086 INT_PTR PropertySheetM(LPCPROPSHEETHEADERA v0)
1089 PROPSHEETHEADERW a0;
1090 PROPSHEETPAGEW* pwPage;
1093 a0.dwSize = sizeof(PROPSHEETHEADERW);
1094 a0.dwFlags = v0->dwFlags;
1095 a0.hwndParent = v0->hwndParent;
1096 a0.hInstance = v0->hInstance;
1097 if(v0->dwFlags & PSH_USEICONID)
1098 a0.pszIcon = DuplicateMtoW(v0->pszIcon, -1);
1100 a0.hIcon = v0->hIcon;
1101 a0.pszCaption = DuplicateMtoW(v0->pszCaption, -1);
1102 a0.nPages = v0->nPages;
1103 a0.pStartPage = DuplicateMtoW(v0->pStartPage, -1);
1104 if(v0->ppsp && (pwPage = (PROPSHEETPAGEW*)malloc(sizeof(PROPSHEETPAGEW) * v0->nPages)))
1106 for(i = 0; i < v0->nPages; i++)
1108 pwPage[i].dwSize = sizeof(PROPSHEETPAGEW);
1109 pwPage[i].dwFlags = v0->ppsp[i].dwFlags;
1110 pwPage[i].hInstance = v0->ppsp[i].hInstance;
1111 pwPage[i].pszTemplate = DuplicateMtoW(v0->ppsp[i].pszTemplate, -1);
1112 if(v0->ppsp[i].dwFlags & PSP_USEICONID)
1113 pwPage[i].pszIcon = DuplicateMtoW(v0->ppsp[i].pszIcon, -1);
1115 pwPage[i].hIcon = v0->ppsp[i].hIcon;
1116 if(v0->ppsp[i].dwFlags & PSP_USETITLE)
1117 pwPage[i].pszTitle = DuplicateMtoW(v0->ppsp[i].pszTitle, -1);
1118 pwPage[i].pfnDlgProc = v0->ppsp[i].pfnDlgProc;
1119 pwPage[i].lParam = v0->ppsp[i].lParam;
1120 // TODO: pfnCallback
1121 pwPage[i].pfnCallback = v0->ppsp[i].pfnCallback;
1122 pwPage[i].pcRefParent = v0->ppsp[i].pcRefParent;
1123 // pwPage[i].pszHeaderTitle = DuplicateMtoW(v0->ppsp[i].pszHeaderTitle, -1);
1124 // pwPage[i].pszHeaderSubTitle = DuplicateMtoW(v0->ppsp[i].pszHeaderSubTitle, -1);
1125 pwPage[i].hActCtx = v0->ppsp[i].hActCtx;
1126 // pwPage[i].pszbmHeader = DuplicateMtoW(v0->ppsp[i].pszbmHeader, -1);
1132 a0.pfnCallback = v0->pfnCallback;
1133 r = PropertySheetW(&a0);
1134 if(a0.dwFlags & PSH_USEICONID)
1135 FreeDuplicatedString(a0.pszIcon);
1136 FreeDuplicatedString(a0.pszCaption);
1137 FreeDuplicatedString(a0.pStartPage);
1140 for(i = 0; i < v0->nPages; i++)
1142 FreeDuplicatedString(pwPage[i].pszTemplate);
1143 if(pwPage[i].dwFlags & PSP_USEICONID)
1144 FreeDuplicatedString(pwPage[i].pszIcon);
1145 if(pwPage[i].dwFlags & PSP_USETITLE)
1146 FreeDuplicatedString(pwPage[i].pszTitle);
1147 // FreeDuplicatedString(pwPage[i].pszHeaderTitle);
1148 // FreeDuplicatedString(pwPage[i].pszHeaderSubTitle);
1149 // FreeDuplicatedString(pwPage[i].pszbmHeader);
1157 BOOL GetOpenFileNameM(LPOPENFILENAMEA v0)
1160 wchar_t* pw0 = NULL;
1161 wchar_t* pw1 = NULL;
1162 wchar_t* pw2 = NULL;
1163 wchar_t* pw3 = NULL;
1164 wchar_t* pw4 = NULL;
1165 wchar_t* pw5 = NULL;
1166 wchar_t* pw6 = NULL;
1167 wchar_t* pw7 = NULL;
1168 wchar_t* pw8 = NULL;
1169 wchar_t* pw9 = NULL;
1172 wofn.lStructSize = sizeof(OPENFILENAMEW);
1173 wofn.hwndOwner = v0->hwndOwner;
1174 wofn.hInstance = v0->hInstance;
1175 pw0 = DuplicateMtoWMultiString(v0->lpstrFilter);
1176 wofn.lpstrFilter = pw0;
1177 pw1 = DuplicateMtoWBuffer(v0->lpstrCustomFilter, -1, v0->nMaxCustFilter * 4);
1178 wofn.lpstrCustomFilter = pw1;
1179 wofn.nMaxCustFilter = v0->nMaxCustFilter * 4;
1180 wofn.nFilterIndex = v0->nFilterIndex;
1181 pw2 = DuplicateMtoWMultiStringBuffer(v0->lpstrFile, v0->nMaxFile * 4);
1182 wofn.lpstrFile = pw2;
1183 wofn.nMaxFile = v0->nMaxFile * 4;
1184 pw3 = DuplicateMtoWBuffer(v0->lpstrFileTitle, -1, v0->nMaxFileTitle * 4);
1185 wofn.lpstrFileTitle = pw3;
1186 wofn.nMaxFileTitle = v0->nMaxFileTitle * 4;
1187 pw4 = DuplicateMtoW(v0->lpstrInitialDir, -1);
1188 wofn.lpstrInitialDir = pw4;
1189 pw5 = DuplicateMtoW(v0->lpstrTitle, -1);
1190 wofn.lpstrTitle = pw5;
1191 wofn.Flags = v0->Flags;
1192 wofn.nFileOffset = MtoW(NULL, 0, v0->lpstrFile, v0->nFileOffset);
1193 wofn.nFileExtension = MtoW(NULL, 0, v0->lpstrFile, v0->nFileExtension);
1194 pw6 = DuplicateMtoW(v0->lpstrDefExt, -1);
1195 wofn.lpstrDefExt = pw6;
1196 wofn.lCustData = v0->lCustData;
1197 wofn.lpfnHook = v0->lpfnHook;
1198 wofn.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);
1199 wofn.pvReserved = v0->pvReserved;
1200 wofn.FlagsEx = v0->FlagsEx;
1201 r = GetOpenFileNameW(&wofn);
1202 WtoM(v0->lpstrFile, v0->nMaxFile, wofn.lpstrFile, -1);
1203 TerminateStringM(v0->lpstrFile, v0->nMaxFile);
1204 v0->nFileOffset = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileOffset);
1205 v0->nFileExtension = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileExtension);
1207 FreeDuplicatedString(pw0);
1208 FreeDuplicatedString(pw1);
1209 FreeDuplicatedString(pw2);
1210 FreeDuplicatedString(pw3);
1211 FreeDuplicatedString(pw4);
1212 FreeDuplicatedString(pw5);
1213 FreeDuplicatedString(pw6);
1217 BOOL GetSaveFileNameM(LPOPENFILENAMEA v0)
1220 wchar_t* pw0 = NULL;
1221 wchar_t* pw1 = NULL;
1222 wchar_t* pw2 = NULL;
1223 wchar_t* pw3 = NULL;
1224 wchar_t* pw4 = NULL;
1225 wchar_t* pw5 = NULL;
1226 wchar_t* pw6 = NULL;
1227 wchar_t* pw7 = NULL;
1228 wchar_t* pw8 = NULL;
1229 wchar_t* pw9 = NULL;
1232 wofn.lStructSize = sizeof(OPENFILENAMEW);
1233 wofn.hwndOwner = v0->hwndOwner;
1234 wofn.hInstance = v0->hInstance;
1235 pw0 = DuplicateMtoWMultiString(v0->lpstrFilter);
1236 wofn.lpstrFilter = pw0;
1237 pw1 = DuplicateMtoWBuffer(v0->lpstrCustomFilter, -1, v0->nMaxCustFilter * 4);
1238 wofn.lpstrCustomFilter = pw1;
1239 wofn.nMaxCustFilter = v0->nMaxCustFilter * 4;
1240 wofn.nFilterIndex = v0->nFilterIndex;
1241 pw2 = DuplicateMtoWMultiStringBuffer(v0->lpstrFile, v0->nMaxFile * 4);
1242 wofn.lpstrFile = pw2;
1243 wofn.nMaxFile = v0->nMaxFile * 4;
1244 pw3 = DuplicateMtoWBuffer(v0->lpstrFileTitle, -1, v0->nMaxFileTitle * 4);
1245 wofn.lpstrFileTitle = pw3;
1246 wofn.nMaxFileTitle = v0->nMaxFileTitle * 4;
1247 pw4 = DuplicateMtoW(v0->lpstrInitialDir, -1);
1248 wofn.lpstrInitialDir = pw4;
1249 pw5 = DuplicateMtoW(v0->lpstrTitle, -1);
1250 wofn.lpstrTitle = pw5;
1251 wofn.Flags = v0->Flags;
1252 wofn.nFileOffset = MtoW(NULL, 0, v0->lpstrFile, v0->nFileOffset);
1253 wofn.nFileExtension = MtoW(NULL, 0, v0->lpstrFile, v0->nFileExtension);
1254 pw6 = DuplicateMtoW(v0->lpstrDefExt, -1);
1255 wofn.lpstrDefExt = pw6;
1256 wofn.lCustData = v0->lCustData;
1257 wofn.lpfnHook = v0->lpfnHook;
1258 wofn.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);
1259 wofn.pvReserved = v0->pvReserved;
1260 wofn.FlagsEx = v0->FlagsEx;
1261 r = GetSaveFileNameW(&wofn);
1262 WtoM(v0->lpstrFile, v0->nMaxFile, wofn.lpstrFile, -1);
1263 TerminateStringM(v0->lpstrFile, v0->nMaxFile);
1264 v0->nFileOffset = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileOffset);
1265 v0->nFileExtension = WtoM(NULL, 0, wofn.lpstrFile, wofn.nFileExtension);
1267 FreeDuplicatedString(pw0);
1268 FreeDuplicatedString(pw1);
1269 FreeDuplicatedString(pw2);
1270 FreeDuplicatedString(pw3);
1271 FreeDuplicatedString(pw4);
1272 FreeDuplicatedString(pw5);
1273 FreeDuplicatedString(pw6);
1277 HWND HtmlHelpM(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData)
1280 wchar_t* pw0 = NULL;
1282 pw0 = DuplicateMtoW(pszFile, -1);
1283 r = HtmlHelpW(hwndCaller, pw0, uCommand, dwData);
1285 FreeDuplicatedString(pw0);
1289 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)
1292 wchar_t* pw0 = NULL;
1293 wchar_t* pw1 = NULL;
1294 wchar_t* pw2 = NULL;
1295 wchar_t* pw3 = NULL;
1296 wchar_t* pw4 = NULL;
1297 wchar_t* pw5 = NULL;
1298 STARTUPINFOW wStartupInfo;
1300 pw0 = DuplicateMtoW(lpApplicationName, -1);
1301 pw1 = DuplicateMtoWBuffer(lpCommandLine, -1, (strlen(lpCommandLine) + 1) * 4);
1302 pw2 = DuplicateMtoW(lpCurrentDirectory, -1);
1303 wStartupInfo.cb = sizeof(LPSTARTUPINFOW);
1304 pw3 = DuplicateMtoW(lpStartupInfo->lpReserved, -1);
1305 wStartupInfo.lpReserved = pw3;
1306 pw4 = DuplicateMtoW(lpStartupInfo->lpDesktop, -1);
1307 wStartupInfo.lpDesktop = pw4;
1308 pw5 = DuplicateMtoW(lpStartupInfo->lpTitle, -1);
1309 wStartupInfo.lpTitle = pw5;
1310 wStartupInfo.dwX = lpStartupInfo->dwX;
1311 wStartupInfo.dwY = lpStartupInfo->dwY;
1312 wStartupInfo.dwXSize = lpStartupInfo->dwXSize;
1313 wStartupInfo.dwYSize = lpStartupInfo->dwYSize;
1314 wStartupInfo.dwXCountChars = lpStartupInfo->dwXCountChars;
1315 wStartupInfo.dwYCountChars = lpStartupInfo->dwYCountChars;
1316 wStartupInfo.dwFillAttribute = lpStartupInfo->dwFillAttribute;
1317 wStartupInfo.dwFlags = lpStartupInfo->dwFlags;
1318 wStartupInfo.wShowWindow = lpStartupInfo->wShowWindow;
1319 wStartupInfo.cbReserved2 = lpStartupInfo->cbReserved2;
1320 wStartupInfo.lpReserved2 = lpStartupInfo->lpReserved2;
1321 wStartupInfo.hStdInput = lpStartupInfo->hStdInput;
1322 wStartupInfo.hStdOutput = lpStartupInfo->hStdOutput;
1323 wStartupInfo.hStdError = lpStartupInfo->hStdError;
1324 r = CreateProcessW(pw0, pw1, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, pw2, &wStartupInfo, lpProcessInformation);
1325 WtoM(lpCommandLine, strlen(lpCommandLine) + 1, pw1, -1);
1327 FreeDuplicatedString(pw0);
1328 FreeDuplicatedString(pw1);
1329 FreeDuplicatedString(pw2);
1330 FreeDuplicatedString(pw3);
1331 FreeDuplicatedString(pw4);
1332 FreeDuplicatedString(pw5);
1336 HINSTANCE FindExecutableM(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
1339 wchar_t* pw0 = NULL;
1340 wchar_t* pw1 = NULL;
1341 wchar_t* pw2 = NULL;
1342 wchar_t* pw3 = NULL;
1344 pw0 = DuplicateMtoW(lpFile, -1);
1345 pw1 = DuplicateMtoW(lpDirectory, -1);
1346 pw2 = AllocateStringW(MAX_PATH * 4);
1347 r = FindExecutableW(pw0, pw1, pw2);
1348 // バッファ長不明のためオーバーランの可能性あり
1349 WtoM(lpResult, MAX_PATH, pw2, -1);
1350 TerminateStringM(lpResult, MAX_PATH);
1352 FreeDuplicatedString(pw0);
1353 FreeDuplicatedString(pw1);
1354 FreeDuplicatedString(pw2);
1355 FreeDuplicatedString(pw3);
1359 HINSTANCE ShellExecuteM(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd)
1362 wchar_t* pw0 = NULL;
1363 wchar_t* pw1 = NULL;
1364 wchar_t* pw2 = NULL;
1365 wchar_t* pw3 = NULL;
1367 pw0 = DuplicateMtoW(lpOperation, -1);
1368 pw1 = DuplicateMtoW(lpFile, -1);
1369 pw2 = DuplicateMtoW(lpParameters, -1);
1370 pw3 = DuplicateMtoW(lpDirectory, -1);
1371 r = ShellExecuteW(hwnd, pw0, pw1, pw2, pw3, nShowCmd);
1373 FreeDuplicatedString(pw0);
1374 FreeDuplicatedString(pw1);
1375 FreeDuplicatedString(pw2);
1376 FreeDuplicatedString(pw3);
1380 PIDLIST_ABSOLUTE SHBrowseForFolderM(LPBROWSEINFOA lpbi)
1382 PIDLIST_ABSOLUTE r = NULL;
1383 wchar_t* pw0 = NULL;
1384 wchar_t* pw1 = NULL;
1387 wbi.hwndOwner = lpbi->hwndOwner;
1388 wbi.pidlRoot = lpbi->pidlRoot;
1389 pw0 = DuplicateMtoWBuffer(lpbi->pszDisplayName, -1, MAX_PATH * 4);
1390 wbi.pszDisplayName = pw0;
1391 pw1 = DuplicateMtoW(lpbi->lpszTitle, -1);
1392 wbi.lpszTitle = pw1;
1393 wbi.ulFlags = lpbi->ulFlags;
1395 wbi.lpfn = lpbi->lpfn;
1396 wbi.lParam = lpbi->lParam;
1397 wbi.iImage = lpbi->iImage;
1398 r = SHBrowseForFolderW(&wbi);
1399 // バッファ長不明のためオーバーランの可能性あり
1400 WtoM(lpbi->pszDisplayName, MAX_PATH, wbi.pszDisplayName, -1);
1401 lpbi->iImage = wbi.iImage;
1403 FreeDuplicatedString(pw0);
1404 FreeDuplicatedString(pw1);
1408 BOOL SHGetPathFromIDListM(PCIDLIST_ABSOLUTE pidl, LPSTR pszPath)
1411 wchar_t* pw0 = NULL;
1413 pw0 = AllocateStringW(MAX_PATH * 4);
1414 r = SHGetPathFromIDListW(pidl, pw0);
1415 // バッファ長不明のためオーバーランの可能性あり
1416 WtoM(pszPath, MAX_PATH, pw0, -1);
1417 TerminateStringM(pszPath, MAX_PATH);
1419 FreeDuplicatedString(pw0);
1423 int SHFileOperationM(LPSHFILEOPSTRUCTA lpFileOp)
1426 wchar_t* pw0 = NULL;
1427 wchar_t* pw1 = NULL;
1428 wchar_t* pw2 = NULL;
1429 SHFILEOPSTRUCTW wFileOp;
1431 wFileOp.hwnd = lpFileOp->hwnd;
1432 wFileOp.wFunc = lpFileOp->wFunc;
1433 pw0 = DuplicateMtoWMultiString(lpFileOp->pFrom);
1434 wFileOp.pFrom = pw0;
1435 pw1 = DuplicateMtoWMultiString(lpFileOp->pTo);
1437 wFileOp.fFlags = lpFileOp->fFlags;
1438 wFileOp.fAnyOperationsAborted = lpFileOp->fAnyOperationsAborted;
1439 wFileOp.hNameMappings = lpFileOp->hNameMappings;
1440 pw2 = DuplicateMtoW(lpFileOp->lpszProgressTitle, -1);
1441 r = SHFileOperationW(&wFileOp);
1442 lpFileOp->fAnyOperationsAborted = wFileOp.fAnyOperationsAborted;
1444 FreeDuplicatedString(pw0);
1445 FreeDuplicatedString(pw1);
1446 FreeDuplicatedString(pw2);
1450 BOOL AppendMenuM(HMENU hMenu, UINT uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem)
1453 wchar_t* pw0 = NULL;
1455 if(uFlags & (MF_BITMAP | MF_OWNERDRAW))
1456 r = AppendMenuW(hMenu, uFlags, uIDNewItem, (LPCWSTR)lpNewItem);
1459 pw0 = DuplicateMtoW(lpNewItem, -1);
1460 r = AppendMenuW(hMenu, uFlags, uIDNewItem, pw0);
1463 FreeDuplicatedString(pw0);
1467 BOOL GetMenuItemInfoM(HMENU hmenu, UINT item, BOOL fByPosition, LPMENUITEMINFOA lpmii)
1470 wchar_t* pw0 = NULL;
1473 wmii.cbSize = sizeof(MENUITEMINFOW);
1474 wmii.fMask = lpmii->fMask;
1475 wmii.fType = lpmii->fType;
1476 wmii.fState = lpmii->fState;
1477 wmii.wID = lpmii->wID;
1478 wmii.hSubMenu = lpmii->hSubMenu;
1479 wmii.hbmpChecked = lpmii->hbmpChecked;
1480 wmii.hbmpUnchecked = lpmii->hbmpUnchecked;
1481 wmii.dwItemData = lpmii->dwItemData;
1482 pw0 = DuplicateMtoWBuffer(lpmii->dwTypeData, -1, lpmii->cch * 4);
1483 wmii.dwTypeData = pw0;
1484 wmii.cch = lpmii->cch * 4;
1485 r = GetMenuItemInfoW(hmenu, item, fByPosition, &wmii);
1486 lpmii->fType = wmii.fType;
1487 lpmii->fState = wmii.fState;
1488 lpmii->wID = wmii.wID;
1489 lpmii->hSubMenu = wmii.hSubMenu;
1490 lpmii->hbmpChecked = wmii.hbmpChecked;
1491 lpmii->hbmpUnchecked = wmii.hbmpUnchecked;
1492 lpmii->dwItemData = wmii.dwItemData;
1493 WtoM(lpmii->dwTypeData, lpmii->cch, wmii.dwTypeData, -1);
1494 TerminateStringM(lpmii->dwTypeData, lpmii->cch);
1496 FreeDuplicatedString(pw0);
1500 HFONT CreateFontIndirectM(CONST LOGFONTA *lplf)
1505 wlf.lfHeight = lplf->lfHeight;
1506 wlf.lfWidth = lplf->lfWidth;
1507 wlf.lfEscapement = lplf->lfEscapement;
1508 wlf.lfOrientation = lplf->lfOrientation;
1509 wlf.lfWeight = lplf->lfWeight;
1510 wlf.lfItalic = lplf->lfItalic;
1511 wlf.lfUnderline = lplf->lfUnderline;
1512 wlf.lfStrikeOut = lplf->lfStrikeOut;
1513 wlf.lfCharSet = lplf->lfCharSet;
1514 wlf.lfOutPrecision = lplf->lfOutPrecision;
1515 wlf.lfClipPrecision = lplf->lfClipPrecision;
1516 wlf.lfQuality = lplf->lfQuality;
1517 wlf.lfPitchAndFamily = lplf->lfPitchAndFamily;
1518 MtoW(wlf.lfFaceName, LF_FACESIZE, lplf->lfFaceName, -1);
1519 TerminateStringW(wlf.lfFaceName, LF_FACESIZE);
1520 r = CreateFontIndirect(&wlf);
1525 BOOL ChooseFontM(LPCHOOSEFONTA v0)
1528 wchar_t* pw0 = NULL;
1532 a0.lStructSize = sizeof(CHOOSEFONTW);
1533 a0.hwndOwner = v0->hwndOwner;
1535 if(v0->lpLogFont && (pwlf = (LOGFONTW*)malloc(sizeof(LOGFONTW))))
1537 pwlf->lfHeight = v0->lpLogFont->lfHeight;
1538 pwlf->lfWidth = v0->lpLogFont->lfWidth;
1539 pwlf->lfEscapement = v0->lpLogFont->lfEscapement;
1540 pwlf->lfOrientation = v0->lpLogFont->lfOrientation;
1541 pwlf->lfWeight = v0->lpLogFont->lfWeight;
1542 pwlf->lfItalic = v0->lpLogFont->lfItalic;
1543 pwlf->lfUnderline = v0->lpLogFont->lfUnderline;
1544 pwlf->lfStrikeOut = v0->lpLogFont->lfStrikeOut;
1545 pwlf->lfCharSet = v0->lpLogFont->lfCharSet;
1546 pwlf->lfOutPrecision = v0->lpLogFont->lfOutPrecision;
1547 pwlf->lfClipPrecision = v0->lpLogFont->lfClipPrecision;
1548 pwlf->lfQuality = v0->lpLogFont->lfQuality;
1549 pwlf->lfPitchAndFamily = v0->lpLogFont->lfPitchAndFamily;
1550 MtoW(pwlf->lfFaceName, LF_FACESIZE, v0->lpLogFont->lfFaceName, -1);
1551 TerminateStringW(pwlf->lfFaceName, LF_FACESIZE);
1555 a0.lpLogFont = pwlf;
1556 a0.iPointSize = v0->iPointSize;
1557 a0.Flags = v0->Flags;
1558 a0.rgbColors = v0->rgbColors;
1559 a0.lCustData = v0->lCustData;
1560 a0.lpfnHook = v0->lpfnHook;
1561 a0.lpTemplateName = DuplicateMtoW(v0->lpTemplateName, -1);
1562 a0.hInstance = v0->hInstance;
1563 a0.lpszStyle = DuplicateMtoWBuffer(v0->lpszStyle, -1, LF_FACESIZE * 4);
1564 a0.nFontType = v0->nFontType;
1565 a0.nSizeMin = v0->nSizeMin;
1566 a0.nSizeMax = v0->nSizeMax;
1567 r = ChooseFontW(&a0);
1570 v0->lpLogFont->lfHeight = pwlf->lfHeight;
1571 v0->lpLogFont->lfWidth = pwlf->lfWidth;
1572 v0->lpLogFont->lfEscapement = pwlf->lfEscapement;
1573 v0->lpLogFont->lfOrientation = pwlf->lfOrientation;
1574 v0->lpLogFont->lfWeight = pwlf->lfWeight;
1575 v0->lpLogFont->lfItalic = pwlf->lfItalic;
1576 v0->lpLogFont->lfUnderline = pwlf->lfUnderline;
1577 v0->lpLogFont->lfStrikeOut = pwlf->lfStrikeOut;
1578 v0->lpLogFont->lfCharSet = pwlf->lfCharSet;
1579 v0->lpLogFont->lfOutPrecision = pwlf->lfOutPrecision;
1580 v0->lpLogFont->lfClipPrecision = pwlf->lfClipPrecision;
1581 v0->lpLogFont->lfQuality = pwlf->lfQuality;
1582 v0->lpLogFont->lfPitchAndFamily = pwlf->lfPitchAndFamily;
1583 WtoM(v0->lpLogFont->lfFaceName, LF_FACESIZE, pwlf->lfFaceName, -1);
1584 TerminateStringM(v0->lpLogFont->lfFaceName, LF_FACESIZE);
1586 v0->rgbColors = a0.rgbColors;
1587 WtoM(v0->lpszStyle, LF_FACESIZE, a0.lpszStyle, -1);
1588 TerminateStringM(v0->lpszStyle, LF_FACESIZE);
1589 v0->nFontType = a0.nFontType;
1592 FreeDuplicatedString(a0.lpTemplateName);
1593 FreeDuplicatedString(a0.lpszStyle);
1595 FreeDuplicatedString(pw0);
1599 INT_PTR DialogBoxParamM(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
1602 wchar_t* pw0 = NULL;
1604 pw0 = DuplicateMtoW(lpTemplateName, -1);
1605 r = DialogBoxParamW(hInstance, pw0, hWndParent, lpDialogFunc, dwInitParam);
1607 FreeDuplicatedString(pw0);
1611 HWND CreateDialogParamM(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
1614 wchar_t* pw0 = NULL;
1616 pw0 = DuplicateMtoW(lpTemplateName, -1);
1617 r = CreateDialogParamW(hInstance, pw0, hWndParent, lpDialogFunc, dwInitParam);
1619 FreeDuplicatedString(pw0);
1623 int mkdirM(const char * _Path)
1626 wchar_t* pw0 = NULL;
1628 pw0 = DuplicateMtoW(_Path, -1);
1631 FreeDuplicatedString(pw0);
1635 int _mkdirM(const char * _Path)
1638 wchar_t* pw0 = NULL;
1640 pw0 = DuplicateMtoW(_Path, -1);
1643 FreeDuplicatedString(pw0);
1647 int rmdirM(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 size_t _mbslenM(const unsigned char * _Str)
1674 wchar_t* pw0 = NULL;
1676 pw0 = DuplicateMtoW(_Str, -1);
1679 FreeDuplicatedString(pw0);
1683 unsigned char * _mbschrM(const unsigned char * _Str, unsigned int _Ch)
1685 unsigned char* r = NULL;
1686 wchar_t* pw0 = NULL;
1689 pw0 = DuplicateMtoW(_Str, -1);
1690 // TODO: 非ASCII文字の対応
1691 wr = wcschr(pw0, _Ch);
1695 r = _Str + WtoM(NULL, 0, pw0, -1) - 1;
1698 FreeDuplicatedString(pw0);
1702 unsigned char * _mbsrchrM(const unsigned char * _Str, unsigned int _Ch)
1704 unsigned char* r = NULL;
1705 wchar_t* pw0 = NULL;
1708 pw0 = DuplicateMtoW(_Str, -1);
1709 // TODO: 非ASCII文字の対応
1710 wr = wcsrchr(pw0, _Ch);
1714 r = _Str + WtoM(NULL, 0, pw0, -1) - 1;
1717 FreeDuplicatedString(pw0);
1721 unsigned char * _mbsstrM(const unsigned char * _Str, const unsigned char * _Substr)
1723 unsigned char* r = NULL;
1724 wchar_t* pw0 = NULL;
1725 wchar_t* pw1 = NULL;
1728 pw0 = DuplicateMtoW(_Str, -1);
1729 pw1 = DuplicateMtoW(_Substr, -1);
1730 wr = wcsstr(pw0, pw1);
1734 r = _Str + WtoM(NULL, 0, pw0, -1) - 1;
1737 FreeDuplicatedString(pw0);
1738 FreeDuplicatedString(pw1);
1742 int _mbscmpM(const unsigned char * _Str1, const unsigned char * _Str2)
1745 wchar_t* pw0 = NULL;
1746 wchar_t* pw1 = NULL;
1748 pw0 = DuplicateMtoW(_Str1, -1);
1749 pw1 = DuplicateMtoW(_Str2, -1);
1750 r = wcscmp(pw0, pw1);
1752 FreeDuplicatedString(pw0);
1753 FreeDuplicatedString(pw1);
1757 int _mbsicmpM(const unsigned char * _Str1, const unsigned char * _Str2)
1760 wchar_t* pw0 = NULL;
1761 wchar_t* pw1 = NULL;
1763 pw0 = DuplicateMtoW(_Str1, -1);
1764 pw1 = DuplicateMtoW(_Str2, -1);
1765 r = _wcsicmp(pw0, pw1);
1767 FreeDuplicatedString(pw0);
1768 FreeDuplicatedString(pw1);
1772 int _mbsncmpM(const unsigned char * _Str1, const unsigned char * _Str2, size_t _MaxCount)
1775 wchar_t* pw0 = NULL;
1776 wchar_t* pw1 = NULL;
1778 pw0 = DuplicateMtoW(_Str1, -1);
1779 pw1 = DuplicateMtoW(_Str2, -1);
1780 r = wcsncmp(pw0, pw1, _MaxCount);
1782 FreeDuplicatedString(pw0);
1783 FreeDuplicatedString(pw1);
1787 unsigned char * _mbslwrM(unsigned char * _String)
1789 unsigned char* r = NULL;
1790 wchar_t* pw0 = NULL;
1792 pw0 = DuplicateMtoW(_String, -1);
1795 WtoM(_String, strlen(_String) + 1, pw0, -1);
1797 FreeDuplicatedString(pw0);
1801 unsigned char * _mbsuprM(unsigned char * _String)
1803 unsigned char* r = NULL;
1804 wchar_t* pw0 = NULL;
1806 pw0 = DuplicateMtoW(_String, -1);
1809 WtoM(_String, strlen(_String) + 1, pw0, -1);
1811 FreeDuplicatedString(pw0);
1815 unsigned char * _mbsnincM(const unsigned char * _Str, size_t _Count)
1817 unsigned char* r = NULL;
1818 wchar_t* pw0 = NULL;
1821 pw0 = DuplicateMtoW(_Str, -1);
1822 wr = _wcsninc(pw0, _Count);
1826 r = _Str + WtoM(NULL, 0, pw0, -1) - 1;
1829 FreeDuplicatedString(pw0);