layer_for_unicode に API 追加
- 追加
@@ -1056,6 +1056,27 @@ | ||
1056 | 1056 | } |
1057 | 1057 | } |
1058 | 1058 | |
1059 | +/** | |
1060 | + * MultiByteToWideChar() の TRUNCATE + CP_ACP 版 | |
1061 | + * wchar_t のパス,ファイル名を char に変換するときに使用 | |
1062 | + * | |
1063 | + * @param[in] str_ptr char の文字列 | |
1064 | + * @param[in,out] wstr_ptr wchar_t 文字列出力先ptr | |
1065 | + * @param[in] wstr_len wchar_t 文字列出力先文字数 | |
1066 | + * @return 変換した文字数(L'^0'含む), wcslen(wstr_ptr) + 1 | |
1067 | + */ | |
1068 | +size_t ACPToWideChar_t(const char *str_ptr, wchar_t *wstr_ptr, size_t wstr_len) | |
1069 | +{ | |
1070 | + const DWORD flags = 0; | |
1071 | + size_t out_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, | |
1072 | + str_ptr, -1, | |
1073 | + wstr_ptr, wstr_len); | |
1074 | + if (out_len == wstr_len) { | |
1075 | + wstr_ptr[wstr_len-1] = 0; | |
1076 | + } | |
1077 | + return out_len; | |
1078 | +} | |
1079 | + | |
1059 | 1080 | char *ToCharW(const wchar_t *strW) |
1060 | 1081 | { |
1061 | 1082 | if (strW == NULL) return NULL; |
@@ -58,6 +58,7 @@ | ||
58 | 58 | char32_t *u32_ptr, size_t *u32_len_); |
59 | 59 | int UTF8ToWideChar(const char *u8_ptr, int u8_len, wchar_t *wstr_ptr, int wstr_len); |
60 | 60 | void WideCharToACP_t(const wchar_t *wstr_ptr, char *mb_ptr, size_t mb_len); |
61 | +size_t ACPToWideChar_t(const char *str_ptr, wchar_t *wstr_ptr, size_t wstr_len); | |
61 | 62 | |
62 | 63 | // API wrappers |
63 | 64 | char *_WideCharToMultiByte(const wchar_t *wstr_ptr, size_t wstr_len, int code_page, size_t *mb_len_); |
@@ -38,7 +38,7 @@ | ||
38 | 38 | #include "ttlib.h" |
39 | 39 | |
40 | 40 | // for debug |
41 | -//#define UNICODE_API_DISABLE 1 | |
41 | +#define UNICODE_API_DISABLE 1 | |
42 | 42 | |
43 | 43 | ATOM (WINAPI *pRegisterClassW)(const WNDCLASSW *lpWndClass); |
44 | 44 | HWND (WINAPI *pCreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, |
@@ -84,6 +84,7 @@ | ||
84 | 84 | DWORD (WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault, |
85 | 85 | LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName); |
86 | 86 | BOOL (WINAPI *pWritePrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpString, LPCWSTR lpFileName); |
87 | +UINT (WINAPI *pGetPrivateProfileIntW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, INT nDefault, LPCWSTR lpFileName); | |
87 | 88 | BOOL (WINAPI *pCreateProcessW)(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, |
88 | 89 | LPSECURITY_ATTRIBUTES lpProcessAttributes, |
89 | 90 | LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, |
@@ -102,6 +103,8 @@ | ||
102 | 103 | HMODULE (WINAPI *pLoadLibraryW)(LPCWSTR lpLibFileName); |
103 | 104 | DWORD (WINAPI *pGetModuleFileNameW)(HMODULE hModule, LPWSTR lpFilename, DWORD nSize); |
104 | 105 | DWORD (WINAPI *pExpandEnvironmentStringsW)(LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize); |
106 | +DWORD (WINAPI *pGetTempPathW)(DWORD nBufferLength, LPWSTR lpBuffer); | |
107 | +UINT (WINAPI *pGetTempFileNameW)(LPCWSTR lpPathName, LPCWSTR lpPrefixString, UINT uUnique, LPWSTR lpTempFileName); | |
105 | 108 | |
106 | 109 | // gdi32 |
107 | 110 | int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res); |
@@ -251,6 +254,7 @@ | ||
251 | 254 | { "SetCurrentDirectoryW", (void **)&pSetCurrentDirectoryW }, |
252 | 255 | { "GetPrivateProfileStringW", (void **)&pGetPrivateProfileStringW }, |
253 | 256 | { "WritePrivateProfileStringW", (void **)&pWritePrivateProfileStringW }, |
257 | + { "GetPrivateProfileIntW", (void **)&pGetPrivateProfileIntW }, | |
254 | 258 | { "CreateProcessW", (void **)&pCreateProcessW }, |
255 | 259 | { "CopyFileW", (void **)&pCopyFileW }, |
256 | 260 | { "DeleteFileW", (void **)&pDeleteFileW }, |
@@ -263,6 +267,8 @@ | ||
263 | 267 | { "LoadLibraryW", (void **)&pLoadLibraryW }, |
264 | 268 | { "GetModuleFileNameW", (void **)&pGetModuleFileNameW }, |
265 | 269 | { "ExpandEnvironmentStringsW", (void **)&pExpandEnvironmentStringsW }, |
270 | + { "GetTempPathW", (void **)&pGetTempPathW }, | |
271 | + { "GetTempFileNameW", (void **)&pGetTempFileNameW }, | |
266 | 272 | #endif |
267 | 273 | { "GetConsoleWindow", (void **)&pGetConsoleWindow }, |
268 | 274 | {}, |
@@ -363,7 +369,11 @@ | ||
363 | 369 | pFindFirstFileW = NULL; |
364 | 370 | pFindNextFileW = NULL; |
365 | 371 | pRemoveDirectoryW = NULL; |
372 | + pGetPrivateProfileIntW = NULL; | |
366 | 373 | pGetModuleFileNameW = NULL; |
374 | + pLoadLibraryW = NULL; | |
375 | + pGetTempPathW = NULL; | |
376 | + pGetTempFileNameW = NULL; | |
367 | 377 | } |
368 | 378 | |
369 | 379 | // GetConsoleWindow特別処理 |
@@ -79,8 +79,6 @@ | ||
79 | 79 | extern BOOL(WINAPI *pModifyMenuW)(HMENU hMnu, UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, LPCWSTR lpNewItem); |
80 | 80 | extern int(WINAPI *pGetMenuStringW)(HMENU hMenu, UINT uIDItem, LPWSTR lpString, int cchMax, UINT flags); |
81 | 81 | extern BOOL(WINAPI *pSetWindowTextW)(HWND hWnd, LPCWSTR lpString); |
82 | -extern DWORD(WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault, | |
83 | - LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName); | |
84 | 82 | extern UINT(WINAPI *pDragQueryFileW)(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch); |
85 | 83 | extern BOOL (WINAPI *pSetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPCWSTR lpString); |
86 | 84 | extern BOOL (WINAPI *pGetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int cchMax); |
@@ -128,6 +126,7 @@ | ||
128 | 126 | extern DWORD (WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault, |
129 | 127 | LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName); |
130 | 128 | extern BOOL (WINAPI *pWritePrivateProfileStringW)(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpString,LPCWSTR lpFileName); |
129 | +extern UINT (WINAPI *pGetPrivateProfileIntW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, INT nDefault, LPCWSTR lpFileName); | |
131 | 130 | extern BOOL (WINAPI *pCreateProcessW)(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, |
132 | 131 | LPSECURITY_ATTRIBUTES lpProcessAttributes, |
133 | 132 | LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, |
@@ -160,6 +159,8 @@ | ||
160 | 159 | extern HMODULE (WINAPI *pLoadLibraryW)(LPCWSTR lpLibFileName); |
161 | 160 | extern DWORD (WINAPI *pGetModuleFileNameW)(HMODULE hModule, LPWSTR lpFilename, DWORD nSize); |
162 | 161 | extern DWORD (WINAPI *pExpandEnvironmentStringsW)(LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize); |
162 | +extern DWORD (WINAPI *pGetTempPathW)(DWORD nBufferLength, LPWSTR lpBuffer); | |
163 | +extern UINT (WINAPI *pGetTempFileNameW)(LPCWSTR lpPathName, LPCWSTR lpPrefixString, UINT uUnique, LPWSTR lpTempFileName); | |
163 | 164 | |
164 | 165 | // shlobj_core.h |
165 | 166 | extern LPITEMIDLIST (WINAPI *pSHBrowseForFolderW)(LPBROWSEINFOW lpbi); |
@@ -683,6 +683,22 @@ | ||
683 | 683 | return r; |
684 | 684 | } |
685 | 685 | |
686 | +UINT _GetPrivateProfileIntW(LPCWSTR lpAppName, LPCWSTR lpKeyName, INT nDefault, LPCWSTR lpFileName) | |
687 | +{ | |
688 | + if (pGetPrivateProfileIntW != NULL) { | |
689 | + return pGetPrivateProfileIntW(lpAppName, lpKeyName, nDefault, lpFileName); | |
690 | + } | |
691 | + | |
692 | + char *appA = ToCharW(lpAppName); | |
693 | + char *keyA = ToCharW(lpKeyName); | |
694 | + char *fileA = ToCharW(lpFileName); | |
695 | + UINT r = GetPrivateProfileIntA(appA, keyA, nDefault, fileA); | |
696 | + free(appA); | |
697 | + free(keyA); | |
698 | + free(fileA); | |
699 | + return r; | |
700 | +} | |
701 | + | |
686 | 702 | BOOL _CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, |
687 | 703 | LPSECURITY_ATTRIBUTES lpProcessAttributes, |
688 | 704 | LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, |
@@ -887,11 +903,11 @@ | ||
887 | 903 | |
888 | 904 | char filenameA[MAX_PATH]; |
889 | 905 | DWORD r = GetModuleFileNameA(hModule, filenameA, sizeof(filenameA)); |
890 | - wchar_t *bufW = ToWcharA(filenameA); | |
891 | - wcsncpy_s(lpFilename, nSize, bufW, _TRUNCATE); | |
892 | - r = (DWORD)wcslen(lpFilename); | |
893 | - free(bufW); | |
894 | - return r; | |
906 | + if (r == 0) { | |
907 | + return 0; | |
908 | + } | |
909 | + DWORD wlen = ACPToWideChar_t(filenameA, lpFilename, nSize); | |
910 | + return wlen - 1; // not including the terminating null character | |
895 | 911 | } |
896 | 912 | |
897 | 913 | DWORD _ExpandEnvironmentStringsW(LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize) |
@@ -910,3 +926,53 @@ | ||
910 | 926 | free(dstW); |
911 | 927 | return r; |
912 | 928 | } |
929 | + | |
930 | +HMODULE _GetModuleHandleW(LPCWSTR lpModuleName) | |
931 | +{ | |
932 | + char *lpStringA = ToCharW(lpModuleName); | |
933 | + HMODULE h = GetModuleHandleA(lpStringA); | |
934 | + free(lpStringA); | |
935 | + return h; | |
936 | +} | |
937 | + | |
938 | +UINT _GetSystemDirectoryW(LPWSTR lpBuffer, UINT uSize) | |
939 | +{ | |
940 | + char buf[MAX_PATH]; | |
941 | + UINT r = GetSystemDirectoryA(buf, _countof(buf)); | |
942 | + if (r == 0) { | |
943 | + return 0; | |
944 | + } | |
945 | + size_t wlen = ACPToWideChar_t(buf, lpBuffer, uSize); | |
946 | + return wlen - 1; // not including the terminating null character | |
947 | +} | |
948 | + | |
949 | +DWORD _GetTempPathW(DWORD nBufferLength, LPWSTR lpBuffer) | |
950 | +{ | |
951 | + if (pGetTempPathW != NULL) { | |
952 | + return pGetTempPathW(nBufferLength, lpBuffer); | |
953 | + } | |
954 | + | |
955 | + char buf[MAX_PATH]; | |
956 | + DWORD r = GetTempPathA(_countof(buf), buf); | |
957 | + if (r == 0) { | |
958 | + return 0; | |
959 | + } | |
960 | + size_t wlen = ACPToWideChar_t(buf, lpBuffer, nBufferLength); | |
961 | + return wlen - 1; // not including the terminating null character | |
962 | +} | |
963 | + | |
964 | +UINT _GetTempFileNameW(LPCWSTR lpPathName, LPCWSTR lpPrefixString, UINT uUnique, LPWSTR lpTempFileName) | |
965 | +{ | |
966 | + if (pGetTempFileNameW != NULL) { | |
967 | + return pGetTempFileNameW(lpPathName, lpPrefixString, uUnique, lpTempFileName); | |
968 | + } | |
969 | + | |
970 | + char buf[MAX_PATH]; | |
971 | + char *lpPathNameA = ToCharW(lpPathName); | |
972 | + char *lpPrefixStringA = ToCharW(lpPrefixString); | |
973 | + UINT r = GetTempFileNameA(lpPathNameA, lpPrefixStringA, uUnique, buf); | |
974 | + ACPToWideChar_t(buf, lpTempFileName, MAX_PATH); | |
975 | + free(lpPathNameA); | |
976 | + free(lpPrefixStringA); | |
977 | + return r; | |
978 | +} |
@@ -121,6 +121,7 @@ | ||
121 | 121 | DWORD _GetPrivateProfileStringW(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault, |
122 | 122 | LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName); |
123 | 123 | BOOL _WritePrivateProfileStringW(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpString,LPCWSTR lpFileName); |
124 | +UINT _GetPrivateProfileIntW(LPCWSTR lpAppName, LPCWSTR lpKeyName, INT nDefault, LPCWSTR lpFileName); | |
124 | 125 | BOOL _CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, |
125 | 126 | LPSECURITY_ATTRIBUTES lpProcessAttributes, |
126 | 127 | LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, |
@@ -139,6 +140,10 @@ | ||
139 | 140 | HMODULE _LoadLibraryW(LPCWSTR lpLibFileName); |
140 | 141 | DWORD _GetModuleFileNameW(HMODULE hModule, LPWSTR lpFilename, DWORD nSize); |
141 | 142 | DWORD _ExpandEnvironmentStringsW(LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize); |
143 | +HMODULE _GetModuleHandleW(LPCWSTR lpModuleName); | |
144 | +UINT _GetSystemDirectoryW(LPWSTR lpBuffer, UINT uSize); | |
145 | +DWORD _GetTempPathW(DWORD nBufferLength, LPWSTR lpBuffer); | |
146 | +UINT _GetTempFileNameW(LPCWSTR lpPathName, LPCWSTR lpPrefixString, UINT uUnique, LPWSTR lpTempFileName); | |
142 | 147 | |
143 | 148 | // gdi32.lib |
144 | 149 | int _AddFontResourceW(LPCWSTR lpFileName); |