mmikeww/AHKv2-Gdip

Use StrGet()/StrPut()

Opened this issue · 1 comments

'just me' writes:

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() respectively WStr

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 WStrtype 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)
}