Use StrGet()/StrPut()
Opened this issue · 1 comments
mmikeww commented
all conversions like
Loop, % nCount { Location := NumGet(ci, 76*(A_Index-1)+44) nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0) VarSetCapacity(sString, nSize) DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0) if !InStr(sString, "*" Extension) continue pCodec := &ci+76*(A_Index-1) break }might be replaced by
StrGet() / StrPut()
respectivelyWStr
AHK-just-me commented
As an example:
Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
{
Ptr := A_PtrSize ? "UPtr" : "UInt"
if (!A_IsUnicode)
{
nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0)
VarSetCapacity(wString, nSize*2)
DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
}
return DllCall("gdiplus\GdipDrawString"
, Ptr, pGraphics
, Ptr, A_IsUnicode ? &sString : &wString
, "int", -1
, Ptr, hFont
, Ptr, &RectF
, Ptr, hFormat
, Ptr, pBrush)
}
AHK 1.1 and 2 support a WStr
type for DllCall()
which internally converts the string to Unicode on ANSI builds.
It can safely be used unless the string is updated by the called function. With respect to issue #1 the function can be changed to:
Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
{
return DllCall("gdiplus\GdipDrawString"
, "Ptr", pGraphics
, "WStr", sString
, "int", -1
, "Ptr", hFont
, "Ptr", &RectF
, "Ptr", hFormat
, "Ptr", pBrush)
}