[Ttssh2-commit] [8699] _GetPrivateProfileStringW(), _WritePrivateProfileStringW() を追加

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2020年 4月 12日 (日) 00:55:27 JST


Revision: 8699
          https://osdn.net/projects/ttssh2/scm/svn/commits/8699
Author:   zmatsuo
Date:     2020-04-12 00:55:27 +0900 (Sun, 12 Apr 2020)
Log Message:
-----------
_GetPrivateProfileStringW(), _WritePrivateProfileStringW() を追加

Modified Paths:
--------------
    trunk/teraterm/common/compat_win.cpp
    trunk/teraterm/common/compat_win.h
    trunk/teraterm/common/layer_for_unicode.cpp
    trunk/teraterm/common/layer_for_unicode.h

-------------- next part --------------
Modified: trunk/teraterm/common/compat_win.cpp
===================================================================
--- trunk/teraterm/common/compat_win.cpp	2020-04-11 15:55:18 UTC (rev 8698)
+++ trunk/teraterm/common/compat_win.cpp	2020-04-11 15:55:27 UTC (rev 8699)
@@ -72,9 +72,11 @@
 
 // kernel32.dll
 DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName);
-DWORD (WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault, LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName);
 void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString);
 HWND (WINAPI *pGetConsoleWindow)(void);
+DWORD (WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault,
+										 LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName);
+BOOL (WINAPI *pWritePrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpString, LPCWSTR lpFileName);
 
 // gdi32.lib
 int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res);
@@ -212,10 +214,11 @@
 static const APIInfo Lists_kernel32[] = {
 #ifndef UNICODE_API_DISABLE
 	{ "GetFileAttributesW", (void **)&pGetFileAttributesW },
-	{ "GetPrivateProfileStringW", (void **)&pGetPrivateProfileStringW },
 	{ "OutputDebugStringW", (void **)&pOutputDebugStringW },
 	{ "GetCurrentDirectoryW", (void **)&pGetCurrentDirectoryW },
 	{ "SetCurrentDirectoryW", (void **)&pSetCurrentDirectoryW },
+	{ "GetPrivateProfileStringW", (void **)&pGetPrivateProfileStringW },
+	{ "WritePrivateProfileStringW", (void **)&pWritePrivateProfileStringW },
 #endif
 	{ "GetConsoleWindow", (void **)&pGetConsoleWindow },
 	{},

Modified: trunk/teraterm/common/compat_win.h
===================================================================
--- trunk/teraterm/common/compat_win.h	2020-04-11 15:55:18 UTC (rev 8698)
+++ trunk/teraterm/common/compat_win.h	2020-04-11 15:55:27 UTC (rev 8699)
@@ -126,6 +126,9 @@
 extern BOOL (WINAPI *pSetCurrentDirectoryW)(LPCWSTR lpPathName);
 extern BOOL (WINAPI *pGetOpenFileNameW)(LPOPENFILENAMEW ofnW);
 extern BOOL (WINAPI *pGetSaveFileNameW)(LPOPENFILENAMEW ofnW);
+extern DWORD (WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault,
+										 LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName);
+extern BOOL (WINAPI *pWritePrivateProfileStringW)(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpString,LPCWSTR lpFileName);
 
 // shlobj_core.h
 extern PIDLIST_ABSOLUTE (WINAPI *pSHBrowseForFolderW)(LPBROWSEINFOW lpbi);

Modified: trunk/teraterm/common/layer_for_unicode.cpp
===================================================================
--- trunk/teraterm/common/layer_for_unicode.cpp	2020-04-11 15:55:18 UTC (rev 8698)
+++ trunk/teraterm/common/layer_for_unicode.cpp	2020-04-11 15:55:27 UTC (rev 8699)
@@ -614,3 +614,45 @@
 	::MultiByteToWideChar(CP_ACP, 0, pathA, -1, pszPath, MAX_PATH);
 	return r;
 }
+
+DWORD _GetPrivateProfileStringW(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault,
+								LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName)
+{
+	if (pGetPrivateProfileStringW != NULL) {
+		return pGetPrivateProfileStringW(lpAppName, lpKeyName, lpDefault,
+										 lpReturnedString, nSize, lpFileName);
+	}
+
+	char *buf = (char* )malloc(nSize);
+	char *appA = ToCharW(lpAppName);
+	char *keyA = ToCharW(lpKeyName);
+	char *defA = ToCharW(lpDefault);
+	char *fileA = ToCharW(lpFileName);
+	DWORD r = GetPrivateProfileStringA(appA, keyA, defA, buf, nSize, fileA);
+	::MultiByteToWideChar(CP_ACP, 0, buf, -1, lpReturnedString, nSize);
+	r = (DWORD)wcslen(lpReturnedString);
+	free(appA);
+	free(keyA);
+	free(defA);
+	free(fileA);
+	free(buf);
+	return r;
+}
+
+BOOL _WritePrivateProfileStringW(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpString,LPCWSTR lpFileName)
+{
+	if (pWritePrivateProfileStringW != NULL) {
+		return pWritePrivateProfileStringW(lpAppName, lpKeyName, lpString, lpFileName);
+	}
+
+	char *appA = ToCharW(lpAppName);
+	char *keyA = ToCharW(lpKeyName);
+	char *strA = ToCharW(lpString);
+	char *fileA = ToCharW(lpFileName);
+	BOOL r = WritePrivateProfileStringA(appA, keyA, strA, fileA);
+	free(appA);
+	free(keyA);
+	free(strA);
+	free(fileA);
+	return r;
+}

Modified: trunk/teraterm/common/layer_for_unicode.h
===================================================================
--- trunk/teraterm/common/layer_for_unicode.h	2020-04-11 15:55:18 UTC (rev 8698)
+++ trunk/teraterm/common/layer_for_unicode.h	2020-04-11 15:55:27 UTC (rev 8699)
@@ -117,6 +117,9 @@
 DWORD _GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer);
 BOOL _SetCurrentDirectoryW(LPCWSTR lpPathName);
 void _OutputDebugStringW(LPCWSTR lpOutputString);
+DWORD _GetPrivateProfileStringW(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault,
+								LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName);
+BOOL _WritePrivateProfileStringW(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpString,LPCWSTR lpFileName);
 
 // gdi32.lib
 int _AddFontResourceW(LPCWSTR lpFileName);


Ttssh2-commit メーリングリストの案内
Back to archive index