﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
1317	UDFs & DllStructCreate() & char/wchar --> Unicode/ANSI problem	Zedna	Valik	"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 & ""]"")
	Else
		$tBuffer = DllStructCreate(""char Text["" & $iBuffer & ""]"")
	EndIf

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
	Else
		$tBuffer = DllStructCreate(""char Buffer[4096]"")
	EndIf
	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

}}}
"	Bug	closed		Standard UDFs	3.3.1.6	None	Rejected		
