Click to See Complete Forum and Search --> : IsTextUnicode() Function ?
escap3
July 15th, 2008, 09:37 AM
hi all,
I need a source code that uses IsUnicodeText() function, In fact I want to know how can I use this useful function in my Program ...
can anyone give me a sample for this purpose ?
Thanks all
- escap3
olivthill
July 16th, 2008, 07:34 AM
Here is an example (not tested)char foo[1000];
int t;
t = IS_TEXT_UNICODE_ASCII16;
If (IsTextUnicode(foo, 1000, &t)
// Unicode Ascii16
...
else
// Not Unicode Ascii16
BTW, are you sure it is a "useful function"?
See "Why I don't like the IsTextUnicode API" at http://blogs.msdn.com/michkap/archive/2005/01/30/363308.aspx
0xC0000005
July 16th, 2008, 08:43 AM
Please read the blog post provided by olivthill before going any further with your development.
Normally, a program will be compiled for UNICODE or MBCS and all strings will be one or the other so there is no need to use a function like this.
IsTextUnicode() would typically be used when you have a BYTE buffer of unknown format that was generated outside of your program and you want to determine if it contains UNICODE text.
However, before you use this function I would strongly urge you (again, as olivthill did) to consider whether or not this function is really useful. Perhaps if you told us why you think you need it we could offer better advice.
escap3
July 19th, 2008, 07:48 AM
hey, thanks from your advices, yeap I know that this function maybe return a wrong value & it's not a reliable function .
and as one of you said, in normally, strings in a program will be compiled for UNICODE standard (UTF-16) .
but, suppose a program like notepad .
when you write some text in it, you can save it as the standard you want .
maybe you want to save it as ASCII & then you want to open a text file .
a program like notepad should be check the String format of the file and a Function like IsTextUnicode() need in the program to recognize the String Format of the file my program also need a function to check the String format of a specific file .
do you know any other idea regardless of using IsTextUnicode() for this matter ?
is there any way for recognizing the String Format of a specific file when you want to Open a file in your program ?
anyone can help about this ?
thanks
-escap3
MikeAThon
July 19th, 2008, 01:08 PM
If a plain text file is a Unicode plain text file, then it should be prefixed with a byte order mark. See "Byte Order Mark" at http://msdn.microsoft.com/en-us/library/ms776429(VS.85).aspx
So, the logic of your program might be:
1. check for presence of a byte order mark (BOM). If not present, then the file is ASCII
2. If BOM is present, then the file is Unicode. Check for its format, to determine exactly the the precise type of Unicode encoding
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.