Modify

Opened 14 years ago

Closed 14 years ago

#1467 closed Bug (No Bug)

DllStructSetData not support UTF8

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: 3.3.4.0 Severity: None
Keywords: Cc:

Description

[autoit]
;=========================================================
; Create the struct
; struct {
; int var1;
; unsigned char var2;
; unsigned int var3;
; char var4[128];
; }
;=========================================================
$str = "int;ubyte;uint;char[128]"
$a = DllStructCreate($str)
if @error Then

MsgBox(0,"","Error in DllStructCreate " & @error);
exit

endif

DllStructSetData($a,1,-1)
DllStructSetData($a,2,255)
DllStructSetData($a,3,-1)
DllStructSetData($a,4,"Hello 你好 中文 123") ;look here if string include chinese character the end will be cut some
;maybe stringlen() call not get ture,if string include chinese character
DllStructSetData($a,4,Asc("h"),1)

;=========================================================
; Display info in the struct
;=========================================================
MsgBox(0,"DllStruct","Struct Size: " & DllStructGetSize($a) & @CRLF & _

"Struct pointer: " & DllStructGetPtr($a) & @CRLF & _
"Data:" & @CRLF & _
DllStructGetData($a,1) & @CRLF & _
DllStructGetData($a,2) & @CRLF & _
DllStructGetData($a,3) & @CRLF & _
DllStructGetData($a,4))

;=========================================================
; Free the memory allocated for the struct
;=========================================================
$a = 0

autoit

Attachments (0)

Change History (3)

comment:1 Changed 14 years ago by jchd

There is no built-in support for UTF-8 strings in DllStruct but you can convert a native AutoIt string (UTF-16LE) into/from an UTF-8 encoded array of bytes, which is OK for DllStructs. This way you can pass/receive UTF-8 data to/from DllCall.

Look at the following internal SQLite functions for a working example: SQLite_StringToUtf8Struct and SQLite_Utf8StructToString. Look at how they are used in this UDF.

Post in the help forum or PM if you have any problem making this work for you.

comment:2 Changed 14 years ago by anonymous

(hit wrong button)
Don't forget that AutoIt strings use UTF-16LE (not UTF-8). If all you need if pass/receive native AutoIt strings, then use "wchar[<charlength>]" type in DllStructCreate and "wstr" as parameter format in DllCall.

The DllStructCreate example in the help file incorrectly uses "char" instead of "wchar". It works for English but fails for CJK and most other languages having codepoints > 0x7F.

comment:3 Changed 14 years ago by Jon

  • Resolution set to No Bug
  • Status changed from new to closed

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.