Ward Posted December 17, 2008 Share Posted December 17, 2008 Since AutoIt3A.exe (ANSI Version) will be removed in next release, I think that most UDFs including Windows API should be modified to use wildcard. For example, "str" -> "wstr", and SendMessage -> SendMessageW. Why? Consider following code in WinAPI.au3: Func _WinAPI_GetTextExtentPoint32($hDC, $sText) Local $tSize, $iSize, $aResult $tSize = DllStructCreate($tagSIZE) $iSize = StringLen($sText) $aResult = DllCall("GDI32.dll", "int", "GetTextExtentPoint32", "hwnd", $hDC, "str", $sText, "int", $iSize, "ptr", DllStructGetPtr($tSize)) _WinAPI_Check("_WinAPI_GetTextExtentPoint32", ($aResult[0] = 0), 0, True) Return $tSize EndFunc ;==>_WinAPI_GetTextExtentPoint32 Here $iSize returned by StringLen() is count by wchar, but "GetTextExtentPoint32" is called in ANSI mode, so the result is always incorrect under DBCS systems. The correct code should be: $aResult = DllCall("GDI32.dll", "int", "GetTextExtentPoint32W", "hwnd", $hDC, "wstr", $sText, "int", $iSize, "ptr", DllStructGetPtr($tSize)) 新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了。 Link to comment Share on other sites More sharing options...
Zedna Posted December 17, 2008 Share Posted December 17, 2008 (edited) Sounds logical.Maybe this should be posted in Bug Track system as BUG. Edited December 17, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
ProgAndy Posted December 17, 2008 Share Posted December 17, 2008 (edited) There is no bug. The lenght of an ANSI string and an Unicode string is the same: ANSI: 1 character: 1 TCHAR -> 1 byte Unicode: 1 character: 1 WCHAR -> 2 bytes --> Stringlen returns number of characters, not bytes. so the size is correct, since the converted string has the same lengtht "str", $sText -> string is given as ANSI But it's a better codingstyle to use Unicode strings and functions in an Unicode application //Edit: but i don't like the default behaviour of the WinAPI funcs uing Exit on Error. It would be better, if you could do error-handlang on your own (At least it should be possible turn off to app exit with a Global Variable.) Edited December 17, 2008 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Ward Posted December 18, 2008 Author Share Posted December 18, 2008 (edited) There is no bug ONLY under NON-DBCS system. In DBCS system, the same string may have different lengh returned by ANSI StringLen() or unicode StringLen(). In fact, the build-in _WinAPI_GetTextExtentPoint32() never get the correct result on my system. Furthermore, some UDF even crash the script because the buffer size of string is wrong. I always use the modified version by myself. Edited December 18, 2008 by Ward 新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了。 Link to comment Share on other sites More sharing options...
ProgAndy Posted December 18, 2008 Share Posted December 18, 2008 Ah, OK. thought, the translation is done correctly in AutoIt... But it's true, that GetExtendPoint won't work since Unicode characters are replaced with a placeholder wich can have an other size. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now