[ros-diffs] [fireball] 49466: [APPS] - Damir Aliev: Properly convert encoding in cmdline tools. See issue #3487 for more details.

fireball at svn.reactos.org fireball at svn.reactos.org
Thu Nov 4 12:28:09 UTC 2010


Author: fireball
Date: Thu Nov  4 12:28:08 2010
New Revision: 49466

URL: http://svn.reactos.org/svn/reactos?rev=49466&view=rev
Log:
[APPS]
- Damir Aliev: Properly convert encoding in cmdline tools.
See issue #3487 for more details.

Modified:
    trunk/reactos/base/applications/network/ipconfig/ipconfig.c
    trunk/reactos/base/system/format/format.c

Modified: trunk/reactos/base/applications/network/ipconfig/ipconfig.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/ipconfig/ipconfig.c?rev=49466&r1=49465&r2=49466&view=diff
==============================================================================
--- trunk/reactos/base/applications/network/ipconfig/ipconfig.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/ipconfig/ipconfig.c [iso-8859-1] Thu Nov  4 12:28:08 2010
@@ -25,6 +25,17 @@
 HINSTANCE hInstance;
 HANDLE ProcessHeap;
 
+int LoadStringAndOem(HINSTANCE hInst,
+		UINT uID,
+		LPTSTR szNode,
+		int Siz
+)	
+{
+  TCHAR szTmp[25];
+  int res = LoadString(hInst, uID, szTmp, sizeof(szTmp)); 
+  CharToOem(szTmp, szNode);
+  return(res);
+}
 
 LPTSTR GetNodeTypeName(UINT NodeType)
 {
@@ -33,27 +44,27 @@
     switch (NodeType)
     {
         case 1:
-            if (!LoadString(hInstance, IDS_BCAST, szNode, sizeof(szNode)))
+            if (!LoadStringAndOem(hInstance, IDS_BCAST, szNode,  sizeof(szNode)))
                 return NULL;
             break;
 
         case 2:
-            if (!LoadString(hInstance, IDS_P2P, szNode, sizeof(szNode)))
+            if (!LoadStringAndOem(hInstance, IDS_P2P, szNode,  sizeof(szNode)))
                 return NULL;
             break;
 
         case 4:
-            if (!LoadString(hInstance, IDS_MIXED, szNode,  sizeof(szNode)))
+            if (!LoadStringAndOem(hInstance, IDS_MIXED, szNode,  sizeof(szNode)))
                 return NULL;
             break;
 
         case 8:
-            if (!LoadString(hInstance, IDS_HYBRID, szNode,  sizeof(szNode)))
+            if (!LoadStringAndOem(hInstance, IDS_HYBRID, szNode,  sizeof(szNode)))
                 return NULL;
             break;
 
         default :
-            if (!LoadString(hInstance, IDS_UNKNOWN, szNode,  sizeof(szNode)))
+            if (!LoadStringAndOem(hInstance, IDS_UNKNOWN, szNode,  sizeof(szNode)))
                 return NULL;
             break;
     }
@@ -69,42 +80,42 @@
     switch (InterfaceType)
     {
         case MIB_IF_TYPE_OTHER:
-            if (!LoadString(hInstance, IDS_OTHER, szIntType, sizeof(szIntType)))
+            if (!LoadStringAndOem(hInstance, IDS_OTHER, szIntType, sizeof(szIntType)))
                 return NULL;
             break;
 
         case MIB_IF_TYPE_ETHERNET:
-            if (!LoadString(hInstance, IDS_ETH, szIntType, sizeof(szIntType)))
+            if (!LoadStringAndOem(hInstance, IDS_ETH, szIntType, sizeof(szIntType)))
                 return NULL;
             break;
 
         case MIB_IF_TYPE_TOKENRING:
-            if (!LoadString(hInstance, IDS_TOKEN, szIntType, sizeof(szIntType)))
+            if (!LoadStringAndOem(hInstance, IDS_TOKEN, szIntType, sizeof(szIntType)))
                 return NULL;
             break;
 
         case MIB_IF_TYPE_FDDI:
-            if (!LoadString(hInstance, IDS_FDDI, szIntType, sizeof(szIntType)))
+            if (!LoadStringAndOem(hInstance, IDS_FDDI, szIntType, sizeof(szIntType)))
                 return NULL;
             break;
 
         case MIB_IF_TYPE_PPP:
-            if (!LoadString(hInstance, IDS_PPP, szIntType, sizeof(szIntType)))
+            if (!LoadStringAndOem(hInstance, IDS_PPP, szIntType, sizeof(szIntType)))
                 return NULL;
             break;
 
         case MIB_IF_TYPE_LOOPBACK:
-            if (!LoadString(hInstance, IDS_LOOP, szIntType, sizeof(szIntType)))
+            if (!LoadStringAndOem(hInstance, IDS_LOOP, szIntType, sizeof(szIntType)))
                 return NULL;
             break;
 
         case MIB_IF_TYPE_SLIP:
-            if (!LoadString(hInstance, IDS_SLIP, szIntType, sizeof(szIntType)))
+            if (!LoadStringAndOem(hInstance, IDS_SLIP, szIntType, sizeof(szIntType)))
                 return NULL;
             break;
 
         default:
-            if (!LoadString(hInstance, IDS_UNKNOWN, szIntType, sizeof(szIntType)))
+            if (!LoadStringAndOem(hInstance, IDS_UNKNOWN, szIntType, sizeof(szIntType)))
                 return NULL;
             break;
     }
@@ -153,6 +164,7 @@
 {
     HKEY hKey = NULL;
     LPTSTR ConType = NULL;
+    LPTSTR ConTypeTmp = NULL;
     TCHAR Path[256];
     LPTSTR PrePath  = _T("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\");
     LPTSTR PostPath = _T("\\Connection");
@@ -180,24 +192,34 @@
                            NULL,
                            &dwDataSize) == ERROR_SUCCESS)
         {
+            ConTypeTmp = (LPTSTR)HeapAlloc(ProcessHeap,
+                                        0,
+                                        dwDataSize);
+
             ConType = (LPTSTR)HeapAlloc(ProcessHeap,
                                         0,
                                         dwDataSize);
-            if (ConType)
+            if (ConType && ConTypeTmp)
             {
                 if(RegQueryValueEx(hKey,
                                    _T("Name"),
                                    NULL,
                                    &dwType,
-                                   (PBYTE)ConType,
+                                   (PBYTE)ConTypeTmp,
                                    &dwDataSize) != ERROR_SUCCESS)
                 {
                     HeapFree(ProcessHeap,
                              0,
                              ConType);
 
+                    HeapFree(ProcessHeap,
+                             0,
+                             ConTypeTmp);
+
                     ConType = NULL;
                 }
+
+                if (ConType) CharToOem(ConTypeTmp, ConType);
             }
         }
     }
@@ -674,7 +696,7 @@
             if (lpUsage == NULL)
                 return;
 
-            if (LoadString(hInstance,
+            if (LoadStringAndOem(hInstance,
                            IDS_USAGE,
                            lpUsage,
                            Size))

Modified: trunk/reactos/base/system/format/format.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/format/format.c?rev=49466&r1=49465&r2=49466&view=diff
==============================================================================
--- trunk/reactos/base/system/format/format.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/format/format.c [iso-8859-1] Thu Nov  4 12:28:08 2010
@@ -48,6 +48,19 @@
 };
 
 
+int LoadStringAndOem(HINSTANCE hInst,
+		UINT uID,
+		LPTSTR szStr,
+		int Siz
+)	
+{
+  TCHAR szTmp[RC_STRING_MAX_SIZE];
+  int res = LoadString(hInst, uID, szTmp, sizeof(szTmp)); 
+  CharToOem(szTmp, szStr);
+  return(res);
+}
+
+
 //----------------------------------------------------------------------
 //
 // PrintWin32Error
@@ -171,7 +184,7 @@
 
 	case PROGRESS:
 		percent = (PDWORD) Argument;
-		LoadString( GetModuleHandle(NULL), STRING_COMPLETE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_COMPLETE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		_tprintf(szMsg, *percent);
 		break;
 
@@ -184,7 +197,7 @@
 		status = (PBOOLEAN) Argument;
 		if( *status == FALSE ) {
 
-			LoadString( GetModuleHandle(NULL), STRING_FORMAT_FAIL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+			LoadStringAndOem( GetModuleHandle(NULL), STRING_FORMAT_FAIL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 			_tprintf("%s", szMsg);
 			Error = TRUE;
 		}
@@ -203,7 +216,7 @@
 	case UNKNOWND:
 	case STRUCTUREPROGRESS:
 	case CLUSTERSIZETOOSMALL:
-		LoadString( GetModuleHandle(NULL), STRING_NO_SUPPORT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_SUPPORT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		_tprintf("%s", szMsg);
 		return FALSE;
 	}
@@ -261,7 +274,7 @@
 	BYTE dummy;
 	BOOLEAN lastestVersion;
 
-	LoadString( GetModuleHandle(NULL), STRING_HELP, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+	LoadStringAndOem( GetModuleHandle(NULL), STRING_HELP, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 	if (!LoadFMIFSEntryPoints())
 	{
 		_tprintf(szMsg, ProgramName, _T(""));
@@ -319,7 +332,7 @@
 	// Get function pointers
 	//
 	if( !LoadFMIFSEntryPoints()) {
-		LoadString( GetModuleHandle(NULL), STRING_FMIFS_FAIL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_FMIFS_FAIL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		_tprintf("%s", szMsg);
 		return -1;
 	}
@@ -329,7 +342,7 @@
 	//
 	if( (badArg = ParseCommandLine( argc, argv ))) {
 
-		LoadString( GetModuleHandle(NULL), STRING_UNKNOW_ARG, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_UNKNOW_ARG, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		_tprintf(szMsg, argv[badArg] );
 
 		Usage(argv[0]);
@@ -341,7 +354,7 @@
 	//
 	if( !Drive ) {
 
-		LoadString( GetModuleHandle(NULL), STRING_DRIVE_PARM, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_DRIVE_PARM, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		_tprintf(szMsg);
 		Usage( argv[0] );
 		return -1;
@@ -359,7 +372,7 @@
 	driveType = GetDriveType( RootDirectory );
 
 	if( driveType == 0 ) {
-		LoadString( GetModuleHandle(NULL), STRING_ERROR_DRIVE_TYPE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_ERROR_DRIVE_TYPE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		PrintWin32Error( szMsg, GetLastError());
 		return -1;
 	}
@@ -371,7 +384,7 @@
 	}
 
 	if( driveType != DRIVE_FIXED ) {
-		LoadString( GetModuleHandle(NULL), STRING_INSERT_DISK, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_INSERT_DISK, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		_tprintf(szMsg, RootDirectory[0] );
 		_fgetts( input, sizeof(input)/2, stdin );
 
@@ -386,7 +399,7 @@
 						&serialNumber, &maxComponent, &flags,
 						fileSystem, sizeof(fileSystem)/2)) {
 
-		LoadString( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		PrintWin32Error( szMsg, GetLastError());
 		return -1;
 	}
@@ -396,11 +409,11 @@
 			&totalNumberOfBytes,
 			&totalNumberOfFreeBytes )) {
 
-		LoadString( GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		PrintWin32Error( szMsg, GetLastError());
 		return -1;
 	}
-	LoadString( GetModuleHandle(NULL), STRING_FILESYSTEM, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+	LoadStringAndOem( GetModuleHandle(NULL), STRING_FILESYSTEM, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 	_tprintf(szMsg, fileSystem );
 
 	//
@@ -412,7 +425,7 @@
 
 			while(1 ) {
 
-				LoadString( GetModuleHandle(NULL), STRING_LABEL_NAME_EDIT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+				LoadStringAndOem( GetModuleHandle(NULL), STRING_LABEL_NAME_EDIT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 				_tprintf(szMsg, RootDirectory[0] );
 				_fgetts( input, sizeof(input)/2, stdin );
 				input[ _tcslen( input ) - 1] = 0;
@@ -421,15 +434,15 @@
 
 					break;
 				}
-				LoadString( GetModuleHandle(NULL), STRING_ERROR_LABEL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+				LoadStringAndOem( GetModuleHandle(NULL), STRING_ERROR_LABEL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 				_tprintf("%s", szMsg);
 			}
 		}
 
-		LoadString( GetModuleHandle(NULL), STRING_YN_FORMAT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_YN_FORMAT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		_tprintf(szMsg, RootDirectory[0] );
 
-		LoadString( GetModuleHandle(NULL), STRING_YES_NO_FAQ, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_YES_NO_FAQ, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 
 		while( 1 ) {
 			_fgetts( input, sizeof(input)/2, stdin );
@@ -460,7 +473,7 @@
 		}
 	} else {
 
-		LoadString( GetModuleHandle(NULL), STRING_FAST_FMT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_FAST_FMT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		if( totalNumberOfBytes.QuadPart > 1024*1024*10 ) {
 
 			_tprintf(_T("%s %luM\n"),szMsg, (DWORD) (totalNumberOfBytes.QuadPart/(1024*1024)));
@@ -470,7 +483,7 @@
 			_tprintf(_T("%s %.2fM\n"),szMsg,
 				((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0));
 		}
-		LoadString( GetModuleHandle(NULL), STRING_CREATE_FSYS, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_CREATE_FSYS, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		_tprintf("%s", szMsg);
 	}
 
@@ -488,7 +501,7 @@
 			ClusterSize, FormatExCallback );
 #endif
 	if( Error ) return -1;
-	LoadString( GetModuleHandle(NULL), STRING_FMT_COMPLETE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+	LoadStringAndOem( GetModuleHandle(NULL), STRING_FMT_COMPLETE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 	_tprintf("%s", szMsg);
 
 	//
@@ -503,7 +516,7 @@
 		if( !EnableVolumeCompression( RootDirectory, TRUE )) {
 #endif
 
-			LoadString( GetModuleHandle(NULL), STRING_VOL_COMPRESS, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+			LoadStringAndOem( GetModuleHandle(NULL), STRING_VOL_COMPRESS, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 			_tprintf("%s", szMsg);
 		}
 	}
@@ -520,7 +533,7 @@
 		input[ _tcslen(input)-1] = 0;
 		if( !SetVolumeLabel( RootDirectory, input )) {
 
-			LoadString( GetModuleHandle(NULL), STRING_NO_LABEL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+			LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_LABEL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 			PrintWin32Error(szMsg, GetLastError());
 			return -1;
 		}
@@ -531,7 +544,7 @@
 						&serialNumber, &maxComponent, &flags,
 						fileSystem, sizeof(fileSystem)/2)) {
 
-		LoadString( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		PrintWin32Error( szMsg, GetLastError());
 		return -1;
 	}
@@ -544,12 +557,12 @@
 			&totalNumberOfBytes,
 			&totalNumberOfFreeBytes )) {
 
-		LoadString( GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		PrintWin32Error(szMsg, GetLastError());
 		return -1;
 	}
 
-	LoadString( GetModuleHandle(NULL), STRING_FREE_SPACE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+	LoadStringAndOem( GetModuleHandle(NULL), STRING_FREE_SPACE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 	_tprintf(szMsg, totalNumberOfBytes.QuadPart, totalNumberOfFreeBytes.QuadPart );
 
 	//
@@ -560,11 +573,11 @@
 						&serialNumber, &maxComponent, &flags,
 						fileSystem, sizeof(fileSystem)/2)) {
 
-		LoadString( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+		LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 		PrintWin32Error( szMsg, GetLastError());
 		return -1;
 	}
-	LoadString( GetModuleHandle(NULL), STRING_SERIAL_NUMBER, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
+	LoadStringAndOem( GetModuleHandle(NULL), STRING_SERIAL_NUMBER, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);
 	_tprintf(szMsg, (unsigned int)(serialNumber >> 16),
 					(unsigned int)(serialNumber & 0xFFFF) );
 




More information about the Ros-diffs mailing list