Board index » cppbuilder » Unicode hell....

Unicode hell....


2007-05-12 03:55:54 AM
cppbuilder75
Hi all, must have posted about this problem 5 times now... Each time i get
a bit closer to a solution but i'm still very confused.
I have a need to identify a MS / Windows generated dialog box in order to
send it a message. I'm enumerating all desktop windows to find it. I
cannot identify it by it's class id so i must identify it by it's caption.
This is fine for English versions of Windows as i know the caption that i'm
;looking for. On other language versions, i must store the different
captions in a resource and then provide some sort of look up based on the
system locale. I have coded this all and it all works, i have slowly
compiled a list of all the alternative language version of the caption i am
looking for. However, i run into a problem when i hit non-Latin based
systems i.e. Unicode.
On these systems, i can get the caption but obviously, it is in a Unicode
format and i need to convert this, and my code, so i can deal with it. If i
use a resource editor, i can not see the Unicode values - they are just
displayed are ??????. My understanding from what has been written here, i
need to convert the Unicode characters into there respective escape
characters and then store the escape sequence in my resource file, preceding
it with an L to indicate it is a wide / Unicode string i.e.
STRINGTABLE
{
1, "ASCII caption"
2, L"\x0421\x043f\x0440\x0430\x0432\x043a\x0430"
}
however, i don't seem to be able to do anything with this... I can read it
in using the LoadStringW api but i just get the escape value in my wchar_t
array. Even if i try to display them using MessageBoxW i still just get
garbage displayed.
wchar_t w[1000];
int i = LoadStringW(HInstance, 2, w, 1000);
MessageBoxW(NULL, w, L"test", MB_OK);
Displays ->213f4030323a30
I'm obviously missing something critical here.
1) is there any simple way to convert to the escape character sequence
without hunting through the Character Map utility.
2) am i storing the escape characters correctly in my resource file?
3) am i reading the resource string correctly?
4) is there some sort of conversion that i need to apply before i can use or
compare the Unicode string that i have read in.
5) finally, everything that i read states that the VCL does not support
Unicode. In following with this, all the string properties of the vcl's are
AnisStrings. However, a Russian developer that i know can develop
application in C++Builder that use and display Russian characters within his
applications. I have seen screen shots of his applications and you can
clearly see the Russian characters in the caption of the form. How is this
possible if the vcl does not support Unicode.
Sorry for the essay, i really hope someone can give me the final pointers
that i need
Many, many thanks in advance,
Mike
 
 

Re:Unicode hell....

Mike Collins wrote:
Quote
STRINGTABLE
{
1, "ASCII caption"
2, L"\x0421\x043f\x0440\x0430\x0432\x043a\x0430"
}
Problem is brcc is translating each char into a word:
0004 0032 0031 0004 etc
I wonder if MS does a better job.
I don't like this "solution" but it gets around the problem.
STRINGTABLE
BEGIN
1"\0\x41\0\x53\0\x49\0\x49\0\x20\0\x63\0\x61\0\x70\0\x74\0\x69\0\x6f\0\x6e\0\0"
2 L"\x04\x21\x04\x3f\x04\x40\x04\x30\x04\x32\x04\x3a\x04\x30\0\0"
END
for( int i = 1; i<3; ++i )
{
wchar_t w[1000] = {0};
wchar_t ww[1000] = {0};
int nw;
nw = LoadStringW( _hInstance, i, w, 1000 );
BobsKludge( ww,/*1000,*/ w/*,nw*/ );
MessageBoxW(NULL, ww, L"test", MB_OK);
};
/* should have size constraints */
void _stdcall BobsKludge(
wchar_t*dest, /*int dest_len,*/
wchar_t*src /*,int src_len*/
)
{
while( src[0] | src[1] )
{ *dest = src[0]<<8 | src[1];
++src;
++src;
++dest;
}
}
Yet another method:
RC:
4 RCDATA {L"ASCII Caption\0"}
5 RCDATA {0x0421 0x043f 0x0440 0x0430 0x0432 0x043a 0x0430 0 0}
CODE:
HRSRC hs;
HGLOBAL hg;
wchar_t *w;
hs = FindResource( NULL, (char*)4, RT_RCDATA );
hg = LoadResource( NULL, hs );
w = LockResource( hg );
MessageBoxW(NULL, w, L"RCDATA", MB_OK);
hs = FindResource( NULL, (char*)5, RT_RCDATA );
hg = LoadResource( NULL, hs );
w = LockResource( hg );
MessageBoxW(NULL, w, L"RCDATA", MB_OK);
As to how you can get the text, you might try Word, with
Insert-Symbol.
When done, save as Plain Text then Other Encoding, then Unicode.
0xfeff is added in front of your document. and the values are
ff fe 21 04 3f 04......
Then you can do
5 RCDATA russian.txt
 

Re:Unicode hell....

Hay bob, thanks for the reply - certainly food for thought. It does beg the
question - how in the hell are you meant to, practically, store and use
Unicode strings in a BCB application
"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
 

{smallsort}

Re:Unicode hell....

?"Mike Collins" <its@TheBottomOfThePost>wrote
Quote
question - how in the hell are you meant to, practically, store and use
Unicode strings in a BCB application
Hi,
Just compile your resource script with a resource
compiler other than Brcc32. If you have MS Visual C++
use rc.exe or you can download a freeware resource
compiler from www.jorgon.freeserve.co.uk/
which I use.
Add the produced .res file to your project. Just take care
to not add your resource script(.rc) to your project but
only the .res file.
_Minas Harokopos
------
"Only the virtue's conquests have certainty" Sofokleous Erephyle