Opened 14 years ago

Closed 10 years ago

#1317 closed Bug (Rejected)

UDFs & DllStructCreate() & char/wchar --> Unicode/ANSI problem

Reported by: Zedna Owned by: Valik
Milestone: Component: Standard UDFs
Version: Severity: None
Keywords: Cc:


In latest Autoit version should be used in almost all UDFs wchar instead of char in DllStructCreate(). Of course there are probably some exceptions.

I searched for keyword "DllStructCreate("char" over all UDFs and found these functions where I think it should be corrected:

Func _GUICtrlListView_FindItem($hWnd, $iStart, ByRef $tFindInfo, $sText = "")
	Local $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]")

Func _GUICtrlListView_GetEmptyText($hWnd)
	Local $tText = DllStructCreate("char[4096]")

Func _GUIToolTip_GetTitleBitMap($hWnd)
	Local $tBuffer = DllStructCreate("char Text[4096]")

Func _GUIToolTip_GetTitleText($hWnd)
	Local $tBuffer = DllStructCreate("char Text[4096]")

Here are examples of UDFs where it's handled correctly so they can be used as good template for correction:

Func _GUICtrlListView_SetItem($hWnd, $sText, $iIndex = 0, $iSubItem = 0, $iImage = -1, $iParam = -1, $iIndent = -1)
	Local $iBuffer = StringLen($sText) + 1
	Local $tBuffer
	If _GUICtrlListView_GetUnicodeFormat($hWnd) Then
		$tBuffer = DllStructCreate("wchar Text[" & $iBuffer & "]")
		$tBuffer = DllStructCreate("char Text[" & $iBuffer & "]")

Func _GUICtrlRebar_GetBandText($hWnd, $iIndex)
	If $Debug_RB Then __UDF_ValidateClassName($hWnd, $__REBARCONSTANT_ClassName)

	Local $fUnicode =  _GUICtrlRebar_GetUnicodeFormat($hWnd)

	Local $tINFO = DllStructCreate($tagREBARBANDINFO)
	Local $pINFO = DllStructGetPtr($tINFO)
	Local $iSize = DllStructGetSize($tINFO)
	Local $tBuffer
	Local $iBuffer = 4096
	If $fUnicode Then
		$tBuffer = DllStructCreate("wchar Buffer[4096]")
		$iBuffer *= 2
		$tBuffer = DllStructCreate("char Buffer[4096]")
	Local $pBuffer = DllStructGetPtr($tBuffer)

	DllStructSetData($tINFO, "cbSize", $iSize)
	DllStructSetData($tINFO, "fMask", $RBBIM_TEXT)
	DllStructSetData($tINFO, "cch", $iBuffer)

I found also other functions using char (and not wchar) in DllStructCreate() but at these ones I'm not sure if it's correct or not:

Func _NamedPipes_PeekNamedPipe($hNamedPipe)
	Local $tBuffer = DllStructCreate("char Text[4096]")

Func _Net_Share_ShareAdd($sServer, $sShare, $iType, $sPath, $sComment = "", $iMaxUses = -1)
	Local $tData = DllStructCreate("char Share[512];char Path[512];char Comment[512]")

Func _Net_Share_ShareSetInfo($sServer, $sShare, $sComment, $iMaxUses)
	Local $tData = DllStructCreate("char Comment[512]")
	Local $pComment = DllStructGetPtr($tData, "Comment")
	_WinAPI_MultiByteToWideCharEx($sComment, DllStructGetPtr($tData, "Comment"))

Func _StringReverse($s_String)

	Local $i_len = StringLen($s_String)
	If $i_len < 1 Then Return SetError(1, 0, "")

	Local $t_chars = DllStructCreate("char[" & $i_len + 1 & "]")
	DllStructSetData($t_chars, 1, $s_String)

	Local $a_rev = DllCall("msvcrt.dll", "ptr:cdecl", "_strrev", "ptr", DllStructGetPtr($t_chars))
	If @error Or $a_rev[0] = 0 Then Return SetError(2, 0, "")

	Return DllStructGetData($t_chars, 1)
EndFunc   ;==>_StringReverse

Attachments (0)

Change History (3)

comment:1 Changed 14 years ago by Valik

This ticket will be fixed as part of the work done for #1336.

comment:2 Changed 13 years ago by Jpm

  • Owner changed from Gary to Valik
  • Status changed from new to assigned

comment:3 Changed 10 years ago by Jon

  • Resolution set to Rejected
  • Status changed from assigned 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

as closed The owner will remain Valik.

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

Note: See TracTickets for help on using tickets.