Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use StrGet()/StrPut() #2

Open
mmikeww opened this issue Nov 18, 2016 · 1 comment
Open

Use StrGet()/StrPut() #2

mmikeww opened this issue Nov 18, 2016 · 1 comment

Comments

@mmikeww
Copy link
Owner

mmikeww commented Nov 18, 2016

'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

@AHK-just-me
Copy link
Contributor

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

pa-0 pushed a commit to pa-0/ahk-GDIpLibrarycompilationv1and2 that referenced this issue Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants