DLLCall assistance please for UUP direct apply project - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39845
And ultimately clearing up some issues from a while ago, here:
GUI COMMANDS: COMPLETE RETHINK - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 95#p138495
I'm providing some examples re. DllCall and IntP/UIntP (aka Int*/UInt*) etc, which I believe to be correct.
When using DllCall, sometimes the call requires a pointer to an Int/Int64 etc, you can use VarSetCapacity and NumGet/NumPut to create a variable and read/write from it, but often you can use a shorthand that is much simpler to use.
Using UIntP as an example, sometimes you want to receive data, in which case you need a variable, sometimes you want to send data, in which case can specify a variable or a put a hardcoded number directly into the DllCall line. If you want to both send and receive data using the same UInt, you need a variable.
Some examples:
Code: Select all
;UIntP: receive values
q:: ;Edit control - get text selection start/end points
ControlGet, hCtl, Hwnd,, Edit1, A
DllCall("user32\SendMessage", Ptr,hCtl, UInt,0xB0, UIntP,vPos1, UIntP,vPos2, Ptr) ;EM_GETSEL := 0xB0
MsgBox, % vPos1 " " vPos2
return
;UIntP: receive values (longer alternative)
w:: ;Edit control - get text selection start/end points
ControlGet, hCtl, Hwnd,, Edit1, A
VarSetCapacity(vPos1, 4, 0)
VarSetCapacity(vPos2, 4, 0)
DllCall("user32\SendMessage", Ptr,hCtl, UInt,0xB0, Ptr,&vPos1, Ptr,&vPos2, Ptr) ;EM_GETSEL := 0xB0
vPos1 := NumGet(&vPos1, 0, "UInt")
vPos2 := NumGet(&vPos2, 0, "UInt")
MsgBox, % vPos1 " " vPos2
return
;Int64P: receive values
e:: ;get high-precision duration of event
DllCall("QueryPerformanceFrequency", Int64P,vQPF)
DllCall("QueryPerformanceCounter", Int64P,vQPC1)
Sleep, 1000
DllCall("QueryPerformanceCounter", Int64P,vQPC2)
MsgBox, % (((vQPC2-vQPC1)/vQPF)*1000)
return
;==================================================
;UIntP: send/receive values using the same variable
r:: ;get A_ComputerName/A_UserName manually
;A_ComputerName
;MAX_COMPUTERNAME_LENGTH := 31
VarSetCapacity(vComputerName, 32*2)
vSize := 32
DllCall("kernel32\GetComputerName", Str,vComputerName, UIntP,vSize)
MsgBox, % vSize " " vComputerName
;A_UserName
;UNLEN := 256
VarSetCapacity(vUserName, 257*2)
vSize := 257
DllCall("advapi32\GetUserName", Str,vUserName, UIntP,vSize)
MsgBox, % vSize " " vUserName
return
;UIntP: send/receive values using the same variable (longer alternative)
t:: ;get A_ComputerName/A_UserName manually
;A_ComputerName
;MAX_COMPUTERNAME_LENGTH := 31
VarSetCapacity(vComputerName, 32*2)
VarSetCapacity(vSize, 4)
NumPut(32, &vSize, 0, "UInt")
DllCall("kernel32\GetComputerName", Str,vComputerName, Ptr,&vSize)
vSize := NumGet(&vSize, 0, "UInt")
MsgBox, % vSize " " vComputerName
;A_UserName
;UNLEN := 256
VarSetCapacity(vUserName, 257*2)
VarSetCapacity(vSize, 4)
NumPut(257, &vSize, 0, "UInt")
DllCall("advapi32\GetUserName", Str,vUserName, Ptr,&vSize)
vSize := NumGet(&vSize, 0, "UInt")
MsgBox, % vSize " " vUserName
return
;==================================================
;UIntP: send values
y:: ;date local to date UTC
vDate := A_Now
vDate -= 1601, Seconds
vIntervals1 := vDate*10000000
DllCall("kernel32\LocalFileTimeToFileTime", Int64P,vIntervals1, Int64P,vIntervals2)
vDate := 1601
vDate += % vIntervals2//10000000, Seconds
FormatTime, vDate, % vDate, yyyy-MM-dd HH:mm:ss
MsgBox, % vDate
return
;UIntP: send values (hard-coded)
u:: ;date local to date UTC
vDate := 2000
vDate -= 1601, Seconds
vIntervals1 := vDate*10000000
MsgBox, % vIntervals1
DllCall("kernel32\LocalFileTimeToFileTime", Int64P,125911584000000000, Int64P,vIntervals2)
vDate := 1601
vDate += % vIntervals2//10000000, Seconds
FormatTime, vDate, % vDate, yyyy-MM-dd HH:mm:ss
MsgBox, % vDate
return
;==================================================