Problem with GetStringTypeExW
I use this in a program and I get the real length in a string when I use Combining Diacritical Marks. But my program in Wine in UbubtuStudio 14.04 64bit has a problem with numbers. So it is possible that something has to be native or not for using proper a GetStringTypeExW function?
This is the code:
Private Const CT_CTYPE3 As Byte = &H4
Private Declare Function GetStringTypeExW Lib "kernel32.dll" (ByVal Locale As Long, ByVal dwInfoType As Long, ByVal lpSrcStr As Long, ByVal cchSrc As Long, ByRef lpCharType As Byte) As Long
Public Function RealLen(s$) As Long
Dim A() As Byte, ctype As Long, s1$, i As Long, ll As Long
ctype = CT_CTYPE3
ll = Len(s$)
If ll Then
ReDim A(Len(s$) * 2 + 20)
If GetStringTypeExW(&HB, ctype, StrPtr(s$), -1, A(0)) <> 0 Then
For i = 1 To Len(s$) * 2 - 1 Step 2
If A(i - 1) > 0 Then If A(i) = 0 Then If A(i - 1) < 8 Then ll = ll - 1
Next i
End If
End If
RealLen = ll
End Function
Problem with GetStringTypeExW in Kenrel32
Re: Problem with GetStringTypeExW in Kenrel32
This is the code.
Running in Wine give 2 as RealLen
But running in Windows give 1 as RealLen
Also in DrawText in Wine we get 2 chars print and not one as in Windows
Running in Wine give 2 as RealLen
But running in Windows give 1 as RealLen
Also in DrawText in Wine we get 2 chars print and not one as in Windows
Code: Select all
Private Const CT_CTYPE3 As Byte = &H4
Private Declare Function GetStringTypeExW Lib "kernel32.dll" (ByVal Locale As Long, ByVal dwInfoType As Long, ByVal lpSrcStr As Long, ByVal cchSrc As Long, ByRef lpCharType As Byte) As Long
Private Type RECT
Left As Long
top As Long
Right As Long
Bottom As Long
End Type
Private Const DT_BOTTOM As Long = &H8&
Private Const DT_CALCRECT As Long = &H400&
Private Const DT_CENTER As Long = &H1&
Private Const DT_SINGLELINE As Long = &H20&
Private Const DT_NOCLIP As Long = &H100&
Private Const DT_NOPREFIX As Long = &H800&
Private Declare Function DrawText Lib "user32" Alias "DrawTextW" (ByVal hDC As Long, ByVal lpStr As Long, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Sub Form_Load()
Dim r As RECT, a$
AutoRedraw = True
a$ = ChrW(97) + ChrW(769)
Text1 = RealLen(a$)
CalcRect hDC, a$, r
PrintLineControlSingle hDC, a$, r
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
Caption = RealLen(Text1)
End If
End Sub
Public Function RealLen(s$) As Long
Dim a() As Byte, ctype As Long, s1$, i As Long, ll As Long
ctype = CT_CTYPE3
ll = Len(s$)
If ll Then
ReDim a(Len(s$) * 2 + 20)
If GetStringTypeExW(&HB, ctype, StrPtr(s$), -1, a(0)) <> 0 Then
For i = 1 To Len(s$) * 2 - 1 Step 2
If a(i - 1) > 0 Then If a(i) = 0 Then If a(i - 1) < 8 Then ll = ll - 1
Next i
End If
End If
RealLen = ll
End Function
Private Sub CalcRect(mHdc As Long, c As String, r As RECT)
r.top = 0
r.Left = 0
DrawText mHdc, StrPtr(c), -1, r, DT_CALCRECT Or DT_NOPREFIX Or DT_SINGLELINE Or DT_NOCLIP
End Sub
Private Sub PrintLineControlSingle(mHdc As Long, c As String, r As RECT)
DrawText mHdc, StrPtr(c), -1, r, DT_SINGLELINE Or DT_NOPREFIX Or DT_NOCLIP
End Sub
-
- Level 7
- Posts: 823
- Joined: Thu Aug 27, 2009 6:23 am
Re: Problem with GetStringTypeExW in Kenrel32
Hi,
you probably should file a bug.
you probably should file a bug.