As of the last few hours, I have started the move to AHK_L from AHK basic. Please bear with me if the following sounds noobish but I am quite unfamiliar with COM being of a non programming background.
I believe the problem is with the unicode4ansi line but after banging my head at my desk for quite a while, I decided to finally ask for help.
Sean's code for AHK basic works fine using COM_Unicode4Ansi
I don't know why the following function won't work:
Code:
SetWallpaper(sFile, sOpt) {
;sFile := "wallpaper_name"
;sOpt := "STRETCH"
WPSTYLE_CENTER := 0
WPSTYLE_TILE := 1
WPSTYLE_STRETCH := 2
WPSTYLE_MAX := 3
CLSID := "{75048700-EF1F-11D0-9888-006097DEACF9}"
IID := "{F490EB00-1240-11D1-9888-006097DEACF9}"
pad := ComObjCreate(CLSID, IID)
DllCall(NumGet(NumGet(1*pad)+28), "Uint", pad, "int64P", WPSTYLE_%sOpt%<<32|8, "Uint", 0) ; SetWallpaperOptions
DllCall(NumGet(NumGet(1*pad)+20), "Uint", pad, "Uint", Unicode4Ansi(wFile,sFile), "Uint", 0) ; SetWallpaper
DllCall(NumGet(NumGet(1*pad)+12), "Uint", pad, "Uint", 7)
}
Unicode4Ansi(ByRef wString, sString)
{
nSize := DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0)
VarSetCapacity(wString, nSize * 2)
DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize)
Return &wString
}