I tried converting into v2 with: https://github.com/mmikeww/AHK-v2-script-converter
This error is revcieved. I know very little about DllCalls, and have attempted a few very small scripts, but alas to no avail. What I think I know...
https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefile says that the 2nd argument is the buffer.
We are giving it a 64 integer.
Help with updating, finding another source, ect. are all appreciated.
Off Topic:
I would like some assistance with figuring out DllCalls if possible, so that I may work with them on my own in the future. I currently do not know enough to work on them. Maybe some small examples? (Maybe along the lines of the current topic).
My version of the v2 script
Code: Select all
SendMode("Input") ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir(A_ScriptDir) ; Ensures a consistent starting directory.
#SingleInstance Force
^\::ExitApp()
;capturing current mouse cursor and save to "saved_Cursor.bmp"
F11:: {
CaptureCursor("saved_Cursor.bmp")
return
}
;compare to testCursor.bmp and current mouse cursor
F12:: {
Loop
{
ToolTip(IsMatchCursor("saved_Cursor.bmp")? "Match" : "Unmatch")
Sleep(100)
}
return
}
;---------------------------------------------------------------
; CaptureCursor and IsMatchCursor
;---------------------------------------------------------------
;captureTo: "clipboard"=save to clipboard , "bitmap_handle"=return current cursor bitmap handle.
;return: 0=fail , 1=success
CaptureCursor(captureTo:="A_Clipboard") {
CURSORINFO := Buffer(20, 0), CURSORINFO := Chr(20) ; V1toV2: if 'CURSORINFO' is a UTF-16 string, use 'VarSetStrCapacity(&CURSORINFO, 20)'
ICONINFO := Buffer(A_PtrSize=8? 32:20, 0) ; V1toV2: if 'ICONINFO' is a UTF-16 string, use 'VarSetStrCapacity(&ICONINFO, A_PtrSize=8? 32:20)'
NumPut("UInt", A_PtrSize=8? 24:20, CURSORINFO, 0)
DllCall("GetCursorInfo", "Uint", CURSORINFO)
hCursor := NumGet(CURSORINFO, 8, "Uint")
flags := NumGet(CURSORINFO, 4, "UInt")
if (!hCursor || !flags) {
return 0
}
hCursor := DllCall("CopyIcon", "Uint", hCursor)
DllCall("GetIconInfo", "UPTR", hCursor, "UPTR", ICONINFO)
mDC := DllCall("CreateCompatibleDC", "Uint", 0)
hBM := CreateDIBSection(mDC, 32, 32)
oBM := DllCall("SelectObject", "Uint", mDC, "Uint", hBM)
DllCall("DrawIcon", "Uint", mDC, "int", 0, "int", 0, "Uint", hCursor)
DllCall("DestroyIcon", "Uint", hCursor)
DllCall("SelectObject", "Uint", mDC, "Uint", oBM)
DllCall("DeleteDC", "Uint", mDC)
If (hbmMask := NumGet(ICONINFO, A_PtrSize=8? 16:12, "UPtr")) {
DllCall("DeleteObject", "UPTR", hbmMask)
}
If (hbmColor := NumGet(ICONINFO, A_PtrSize=8? 24:16, "UPtr")) {
DllCall("DeleteObject", "UPTR", hbmColor)
}
if (captureTo=bitmap_handle) {
return hBM
}
If (captureTo=A_Clipboard) {
SetClipboardData(hBM)
} else {
SaveHBITMAPToFile(hBM, captureTo)
DllCall("DeleteObject", "Uint", hBM)
return 1
}
}
;compare cursor bmp file to current mouse cursor.
; 1 : cursor image match
; 0 : cursor image unmatch
; ""; hide mouse cursor or can't get cursor handle.
IsMatchCursor(bmpCursorFile) {
if (!hCursorBmp := CaptureCursor("bitmap_handle")) {
return ""
}
hSourceBmp := LoadBMP(bmpCursorFile)
return !CompareBitmap(hSourceBmp, hCursorBmp, 32)
}
;---------------------------------------------------------------
; Sub function
;---------------------------------------------------------------
;this function takes two bitmaps and compares the first 32x32 pixel square on them
;hBM1 and hBM2: bitmap handle
;return: 0=match, 1=unmatch
CompareBitmap(hBM1, hBM2, size:=32) {
x := "0"
mDC1 := DllCall("CreateCompatibleDC", "Uint", 0) ;create DC compatible with screen
mDC2 := DllCall("CreateCompatibleDC", "Uint", 0)
oBM1 := DllCall("SelectObject", "UPTR", mDC1, "UPTR", hBM1) ;put the object in the device context
oBM2 := DllCall("SelectObject", "UPTR", mDC2, "UPTR", hBM2)
while (x < size) {
y := "0"
while (y < size) {
color1 := DllCall("GetPixel", "UPTR", mDC1, "int", x, "int", y) ;get the RGB of pixel (x, y)
color2 := DllCall("GetPixel", "UPTR", mDC2, "int", x, "int", y)
if (color1 != color2) ;if colors are different, didn't match
return 1
y+=1
}
x+=1
}
DllCall("SelectObject", "UPTR", mDC1, "UPTR", oBM1) ;put the original contents back in DC
DllCall("SelectObject", "UPTR", mDC2, "UPTR", oBM2)
DllCall("DeleteDC", "UPTR", mDC1) ;delete DC (prevent memory leak)
DllCall("DeleteDC", "UPTR", mDC2)
DllCall("DeleteObject", "UPTR", hBM1) ;delete the images in memory
DllCall("DeleteObject", "UPTR", hBM2)
return 0 ;0 return if match
}
CreateDIBSection(hDC, nW, nH, bpp := 32, &pBits := "") {
BITMAPINFO := Buffer(44, 0) ; V1toV2: if 'BITMAPINFO' is a UTF-16 string, use 'VarSetStrCapacity(&BITMAPINFO, 44)'
NumPut("UInt", 44, BITMAPINFO, 0)
NumPut("Int", nW, BITMAPINFO, 4)
NumPut("Int", nH, BITMAPINFO, 8)
NumPut("UShort", 1, BITMAPINFO, 12)
NumPut("UShort", bpp, BITMAPINFO, 14)
Return DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", BITMAPINFO, "Uint", 0, "Uint", pBits, "Uint", 0, "Uint", 0)
}
SetClipboardData(hBitmap) {
DIBSECTION := Buffer(A_PtrSize=8? 104:84, 0) ; V1toV2: if 'DIBSECTION' is a UTF-16 string, use 'VarSetStrCapacity(&DIBSECTION, A_PtrSize=8? 104:84)'
NumPut("UInt", 40, DIBSECTION, A_PtrSize=8? 32:24) ;dsBmih.biSize
DllCall("GetObject", "UPTR", hBitmap, "int", A_PtrSize=8? 104:84, "UPTR", DIBSECTION)
biSizeImage := NumGet(DIBSECTION, A_PtrSize=8? 52:44, "UInt")
hDIB := DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+biSizeImage)
pDIB := DllCall("GlobalLock", "UPTR", hDIB)
DllCall("RtlMoveMemory", "UPTR", pDIB, "UPTR", DIBSECTION + (A_PtrSize=8? 32:24), "Uint", 40)
DllCall("RtlMoveMemory", "UPtr", pDIB+40, "Uint", NumGet(DIBSECTION, A_PtrSize=8? 24:20, "UPtr"), "Uint", biSizeImage)
DllCall("GlobalUnlock", "UPTR", hDIB)
DllCall("DeleteObject", "UPTR", hBitmap)
DllCall("OpenClipboard", "Uint", 0)
DllCall("EmptyClipboard")
DllCall("SetClipboardData", "Uint", 8, "UPTR", hDIB)
DllCall("CloseClipboard")
}
LoadBMP(bmpFile) {
bmpFile := GetValidFilePath(bmpFile)
hBmp := DllCall("LoadImage", "Uint", 0, "str", bmpFile, "Uint", 0, "int", 32, "int", 32, "Uint", 0x00000010) ;load the image from file
return hBmp
}
SaveHBITMAPToFile(hBitmap, sFile) {
sFile := GetValidFilePath(sFile)
DIBSECTION := Buffer(A_PtrSize=8? 104:84, 0) ; V1toV2: if 'DIBSECTION' is a UTF-16 string, use 'VarSetStrCapacity(&DIBSECTION, A_PtrSize=8? 104:84)'
NumPut("UInt", 40, DIBSECTION, A_PtrSize=8? 32:24) ;dsBmih.biSize
DllCall("GetObject", "Uint", hBitmap, "int", A_PtrSize=8? 104:84, "Uint", DIBSECTION)
hFile:= DllCall("CreateFile", "Uint", sFile, "Uint", 0x40000000, "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 0, "Uint", 0)
DllCall("WriteFile", "Uint", hFile, "int64P", &0x4D42|14+40+(biSizeImage:=NumGet(DIBSECTION, A_PtrSize=8? 52:44, "UInt"))<<16, "Uint", 6, "UintP", &0, "Uint", 0)
DllCall("WriteFile", "Uint", hFile, "int64P", &54<<32, "Uint", 8, "UintP", &0, "Uint", 0)
DllCall("WriteFile", "Uint", hFile, "Uint", DIBSECTION + (A_PtrSize=8? 32:24), "Uint", 40, "UintP", &0, "Uint", 0)
DllCall("WriteFile", "Uint", hFile, "Uint", NumGet(DIBSECTION, A_PtrSize=8? 24:20, "UPtr"), "Uint", biSizeImage, "UintP", &0, "Uint", 0)
DllCall("CloseHandle", "Uint", hFile)
}
GetValidFilePath(filename) {
SplitPath(filename, , &sDir, &sExt, &sName)
if !InStr(sDir, ":")
sDir := A_ScriptDir . "\" . sDir
filename := sDir . "\" . sName . "." . sExt
; StrReplace() is not case sensitive
; check for StringCaseSense in v1 source script
; and change the CaseSense param in StrReplace() if necessary
filename := StrReplace(filename, "\\", "\")
return filename
}
;---------------------------------------------------------------
; Struct List
;---------------------------------------------------------------
/*
typedef struct {
DWORD cbSize;
DWORD flags;
HCURSOR hCursor;
POINT ptScreenPos;
} CURSORINFO, *PCURSORINFO, *LPCURSORINFO;
typedef struct _ICONINFO {
BOOL fIcon;
DWORD xHotspot;
DWORD yHotspot;
HBITMAP hbmMask;
HBITMAP hbmColor;
} ICONINFO, *PICONINFO;
typedef struct tagDIBSECTION {
BITMAP dsBm;
BITMAPINFOHEADER dsBmih;
DWORD dsBitfields[3];
HANDLE dshSection;
DWORD dsOffset;
} DIBSECTION, *PDIBSECTION;
typedef struct tagBITMAPINFOHEADER {
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;
typedef struct tagBITMAP {
LONG bmType;
LONG bmWidth;
LONG bmHeight;
LONG bmWidthBytes;
WORD bmPlanes;
WORD bmBitsPixel;
LPVOID bmBits;
} BITMAP, *PBITMAP;
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;
typedef struct tagRGBQUAD {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;
*/