Is IsTextUnicode reliable?

June 20th, 2008 - 02:49 pm ET by RB Smissaert | Report spam
It looks the API IsTextUnicode is not reliable even when it repeatedly runs
on the same string.
So, it can give False or True on the same string. Am I doing something wrong
or is this API indeed
not reliable?

Private Declare Function IsTextUnicode Lib "advapi32" _
(lpBuffer As Any, _
ByVal cb As Long, _
lpi As Long) As Long

Public Function IsUnicodeStr(sBuffer As String) As Boolean

Const IS_TEXT_UNICODE_UNICODE_MASK = &HF

'Returns True if sBuffer evaluates to a Unicode string
Dim dwRtnFlags As Long

'note we need a variable dwRtnFlags here as dwRtnFlags is [in] [out]
'-
dwRtnFlags = IS_TEXT_UNICODE_UNICODE_MASK
IsUnicodeStr = IsTextUnicode(StrPtr(sBuffer), Len(sBuffer), dwRtnFlags)

End Function


RBS
email Follow the discussionReplies 13 repliesReplies Make a reply

Replies

#1 Tony Proctor
June 23rd, 2008 - 06:23 am ET | Report spam
As just about everyone else has said <grin>, VB Strings are always held in
Unicode and so the call isn't very helpful

However, I would like to add that if you've imported some textual data and
you're trying to determine whether the encoding is Unicode or some other
SBCS/DBCS then it should not be imported into String variables. Putting
non-Unicode data into String variables breaks several rules and could cause
run-time errors. Such data should be imported into Byte arrays, and then
calling IsTextUnicode could be useful

Tony Proctor

"RB Smissaert" wrote in message
news:
It looks the API IsTextUnicode is not reliable even when it repeatedly
runs on the same string.
So, it can give False or True on the same string. Am I doing something
wrong or is this API indeed
not reliable?

Private Declare Function IsTextUnicode Lib "advapi32" _
(lpBuffer As Any, _
ByVal cb As Long, _
lpi As Long) As Long

Public Function IsUnicodeStr(sBuffer As String) As Boolean

Const IS_TEXT_UNICODE_UNICODE_MASK = &HF

'Returns True if sBuffer evaluates to a Unicode string
Dim dwRtnFlags As Long

'note we need a variable dwRtnFlags here as dwRtnFlags is [in] [out]
'-
dwRtnFlags = IS_TEXT_UNICODE_UNICODE_MASK
IsUnicodeStr = IsTextUnicode(StrPtr(sBuffer), Len(sBuffer), dwRtnFlags)

End Function


RBS



Similar topics