Home » U++ Library support » U++ Core » Environment variables code page 
	
		
		
			| Environment variables code page [message #22538] | 
			Sat, 25 July 2009 13:05   | 
		 
		
			
				
				
				
					
						  
						Zbych
						 Messages: 328 Registered: July 2009 
						
					 | 
					Senior Member  | 
					 | 
		 
		 
	 | 
 
	
		Hi, 
 
GetEnv function uses FromSystemCharset to convert code page, but environment variables in windows use OEM not ANSI code page. I think that there should be another function - FromOEMCharset (defined only in section PLATFORM_WIN32) and GetEnv should be split in two versions (windows and posix). 
 
App.cpp, line ~10:
#ifdef PLATFORM_WIN32
String GetEnv(const char *id)
{
	return FromOEMCharset(getenv(id));
}
[...]
App.cpp line ~20:
#ifdef PLATFORM_POSIX
String GetEnv(const char *id)
{
	return FromSystemCharset(getenv(id));
}
[...]
Util.cpp line ~620:
String FromOEMCharset(const String& src)
{
	WStringBuffer b(src.GetLength());
	int q = MultiByteToWideChar(CP_OEMCP, MB_PRECOMPOSED, ~src, src.GetLength(), (WCHAR*)~b, src.GetLength());
	if(q <= 0)
		return src;
	b.SetCount(q);
	return WString(b).ToString();
}
 
		
		
		[Updated on: Sat, 25 July 2009 13:05] Report message to a moderator  
 |  
	| 
		
	 | 
 
 
 |  
	
		
		
			| Re: Environment variables code page [message #22540 is a reply to message #22538] | 
			Sun, 26 July 2009 03:26    | 
		 
		
			
				
				
				  | 
					
						  
						mirek
						 Messages: 14271 Registered: November 2005 
						
					 | 
					Ultimate Member  | 
					 | 
		 
		 
	 | 
 
	
		| Zbych wrote on Sat, 25 July 2009 07:05 |   Hi, 
 
GetEnv function uses FromSystemCharset to convert code page, but environment variables in windows use OEM not ANSI code page. I think that there should be another function - FromOEMCharset (defined only in section PLATFORM_WIN32) and GetEnv should be split in two versions (windows and posix). 
 
App.cpp, line ~10:
#ifdef PLATFORM_WIN32
String GetEnv(const char *id)
{
	return FromOEMCharset(getenv(id));
}
[...]
App.cpp line ~20:
#ifdef PLATFORM_POSIX
String GetEnv(const char *id)
{
	return FromSystemCharset(getenv(id));
}
[...]
Util.cpp line ~620:
String FromOEMCharset(const String& src)
{
	WStringBuffer b(src.GetLength());
	int q = MultiByteToWideChar(CP_OEMCP, MB_PRECOMPOSED, ~src, src.GetLength(), (WCHAR*)~b, src.GetLength());
	if(q <= 0)
		return src;
	b.SetCount(q);
	return WString(b).ToString();
}
 
  |  
  
 
OK, I have only tried to size-optimize a little (please check): 
 
String FromWin32Charset(const String& src, int cp)
{
	WStringBuffer b(src.GetLength());
	int q = MultiByteToWideChar(cp, MB_PRECOMPOSED, ~src, src.GetLength(), (WCHAR*)~b, src.GetLength());
	if(q <= 0)
		return src;
	b.SetCount(q);
	return WString(b).ToString();
}
String FromOEMCharset(const String& src)
{
	return FromWin32Charset(src, CP_OEMCP);
}
String FromSystemCharset(const String& src)
{
	return FromWin32Charset(src, CP_ACP);
}
 
 
Mirek
		
		
		
 |  
	| 
		
	 | 
 
 
 |  
	| 
		
 |  
	
		
		
			| Re: Environment variables code page [message #22547 is a reply to message #22538] | 
			Sun, 26 July 2009 11:21   | 
		 
		
			
				
				
				
					
						  
						cbpporter
						 Messages: 1428 Registered: September 2007 
						
					 | 
					Ultimate Contributor  | 
					 | 
		 
		 
	 | 
 
	
		| Zbych wrote on Sat, 25 July 2009 14:05 |  
  
GetEnv function uses FromSystemCharset to convert code page, but environment variables in windows use OEM not ANSI code page. 
  |  
  
This must be the reason why Unicode strings where not recognized in environment variables. I proposed a solution here, but I guess this will work a lot better. I'll try to see if it works correctly.
		
		
		
 |  
	| 
		
	 | 
 
 
 |   
Goto Forum:
 
 Current Time: Tue Nov 04 00:38:17 CET 2025 
 Total time taken to generate the page: 0.04486 seconds 
 |