Codepages

Elrick

Member
Licensed User
Hello! I tried to get owner name and used alfcen's code from here: http://www.b4x.com/forum/code-samples-tips/953-getownername.html
When the name written on english, it shows ok. But when i trying to write it on russian, it shows like abracadabra... I thought it is because of codepages (the system language of my device is russian, so it uses windows-1251 codepage) and tried to use Bitwise library, but has not reached any success...:sign0104: Can anybody help me with it?
 

Cableguy

Expert
Licensed User
Longtime User
have you tryed to actualy navigate to the regestry key and see it's contents?
In my homeland language we have accentuation in some letters like "é ã ê" and others..
I'll see if the code posted works and let you know my findings...
 

Cableguy

Expert
Licensed User
Longtime User
It does work ok...

My OS is an WWE ROM, is yours a Russian ROM, or a WWE ROM?

Try to get the equivalent byte values from the code page e compare to the ones retrieved by the code, changing the line:
B4X:
m = m & Chr(buff(i))

to

B4X:
m = m & buff(i) &","  'This will sepparate the bytes with commas
 
Last edited:

Elrick

Member
Licensed User
the problem is deeper than it looks like. Untill this moment i used registry key "Name" instead of "Owner" and converts it with "Asc" function to generate serial number to my program. But now i found what WM2003SE have no key "Name"... I dont want to rewrite my code, so i tried to add alfcen's code instead of mine. This code returns owner name and then i use "asc". But when the name written on russian, it returns wrong result:

With my short name "Вова" (it is russian letters, not english!) it returns "18 62 50 48" but "Asc" returns "1042 1084 1074 1072" (without spaces of course)
 

Cableguy

Expert
Licensed User
Longtime User
the problem is deeper than it looks like. Untill this moment i used registry key "Name" instead of "Owner" and converts it with "Asc" function to generate serial number to my program. But now i found what WM2003SE have no key "Name"... I dont want to rewrite my code, so i tried to add alfcen's code instead of mine. This code returns owner name and then i use "asc". But when the name written on russian, it returns wrong result:

With my short name "Вова" (it is russian letters, not english!) it returns "18 62 50 48" but "Asc" returns "1042 1084 1074 1072" (without spaces of course)

Try to navigate to local machine\MUI
There you'll find "syslang", whats the hex data? mine reads "0X000409" being the 409 the important data...
 

Cableguy

Expert
Licensed User
Longtime User
try to set the regisnal setting to other than russian and see if this value changes...
mine is set to portuguese so it reads 409...
 

Cableguy

Expert
Licensed User
Longtime User
From this page in msdn, Its clear that chr is code page dependante and that a conversion is possible...
maybe using the door library...
 

Elrick

Member
Licensed User
hm... i set it to portuguese too and after restart my device language was still russian... The "syslang" value didn't changes and still was 0x419 (1049)
 

Cableguy

Expert
Licensed User
Longtime User
Don't reset, it will take on the default values...
My Rom is WWE, so whenever I reset the device, i have to change all it's default values...
I'm quite sure that there should be a way to chnage the code page, by parametring a shelled app...
the question is wich app...
 

Cableguy

Expert
Licensed User
Longtime User
Another interesting link regarding codepages
And yet another link...
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Some new Thoughts based on the links found:

- The device SHOULD support up to 15 keyboard layouts, as long as the proper DLL is provided...

- The Regestry keys

"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Keyboad layout"
"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Layouts"

are responsable for the actual keyboard behavior, and are codepage related.

- In the first key we find the "Active" layout...
- In the second Key we find the available layouts...usualy...just one...
 

agraham

Expert
Licensed User
Longtime User
I don't think that this is anything to do with Code Pages - in the strict sense that a code page used to be used to map different characters to the top 128 bytes of an 8 bit character set.

I believe that the Pocket PC, as well as the Compact Framework, uses Unicode characters which makes code pages obsolete. It is probable, though I don't know for sure, that the name in the Registry is held as a UTF-8 string

Alfcen's code assumes that the name is returned as bytes each of which he transforms into a char. This only a valid assumption if the the characters are in the ASCII character set. In Unicode other characters, such as Russian are held as two or more characters - hence the fact that Asc returns numbers larger than 256 for Russian characters. I would try assigning the return of Reg.GetValue to a string if it will do it without erroring.

UTF-8 has variable character lengths which makes programming strings a pain so .NET uses Unicode UTF-16 format strings in which ALL characters are held as 16 bit characters so obtaining sub-strings and indexing into strings works as you expect. .NET Streams often transform from UTF-8 to UTF-16 and vice-versa on input and output. This is why you have the cASCII parameter in the FileOpen statement. It defines that the stream is treated as purely 8 bit characters. Without cASCII the stream is treated as a stream of UTF-8 characters some of which are 8 and some of which are 16 bits. So on output the .NET UTF-16 string is transformed to either ASCII (with potential loss of unsupported characters) or UTF-8 characters and the reverse happens on input. ASCII streams code pages are supported in .NET so that UTF-16 strings can be converted to pure 8bit character strings and back without losing characters. The Bitwise library New2 constructor supports code pages for byte to and from string conversion but I haven't played with it myself.

Sorry if this is a bit long. Wikipedia has a couple of good articles about Unicode and Code Pages.
 

Cableguy

Expert
Licensed User
Longtime User
Using Agraham's sugestion, I went back to my regestry editor, and searched for the key name, and found ou that it is called "Name".
So instead of going trought the owner info, byte by byte...I eleminated the entire for...next loop and placed the following:

B4X:
MsgBox(reg.GetString("ControlPanel\Owner\","Name"))

And it did return the correct string...
 
Top