DllCall. Help, anyone?
I have a question regarding the LSB. Does it mean an int 1 does look like this in memory( bytes delimited by |)
00000001|00000000|00000000|00000000
and not like this:
00000000|00000000|00000000|00000001
?
olfen wrote:
Interesting.WinHex helped me get started with DllCalls and I am still using it to see what actually is happening in the process memory.
It allows you to open the memory of your running ahk script (Alt-F9) and see what data is present at a certain offset (you can get that offset by evaluating &variable).
I downloaded WinHex.
Could you give some more details about how evaluating &variable?
Thanks
Noel
A useful helper function (overkill here, but of general utility for debugging):
a := 1 MsgBox % DumpDWORDs(a, 4) FormatHexNumber(_value, _digitNb) { local hex, intFormat ; Save original integer format intFormat = %A_FormatInteger% ; For converting bytes to hex SetFormat Integer, Hex hex := _value + (1 << 4 * _digitNb) StringRight hex, hex, _digitNb ; I prefer my hex numbers to be in upper case StringUpper hex, hex ; Restore original integer format SetFormat Integer, %intFormat% Return hex } /* // For debugging, return formatted hex string separating DWORDs // Idem to Bin2Hex, usable directly in a MsgBox... // Extended mode: give offsets and Ascii dump. */ DumpDWORDs(ByRef @bin, _byteNb, _bExtended=false) { local dataSize, dataAddress, granted, line, dump, hex, ascii local dumpWidth, offsetSize, resultSize offsetSize = 4 ; 4 hex digits (enough for most dumps) dumpWidth = 32 dataAddress := &@bin ; Make enough room (faster) resultSize := _byteNb * 4 If _bExtended { dumpWidth = 16 ; Make room for offset and Ascii resultSize += offsetSize + 8 + dumpWidth } granted := VarSetCapacity(dump, resultSize) if (granted < resultSize) { ; Cannot allocate enough memory ErrorLevel = Mem=%granted% Return -1 } If _bExtended { offset = 0 line := FormatHexNumber(offset, offsetSize) ": " } Loop %_byteNb% { ; Get byte in hexa hex := FormatHexNumber(*dataAddress, 2) If _bExtended { ; Get byte in Ascii If (*dataAddress >= 32) ; Not a control char { ascii := ascii Chr(*dataAddress) } Else { ascii := ascii "." } offset++ } line := line hex A_Space If (Mod(A_Index, dumpWidth) = 0) { ; Max dumpWidth bytes per line If (_bExtended) { ; Show Ascii dump line := line " - " ascii ascii = } dump := dump line "`n" line = If (_bExtended && A_Index < _byteNb) { line := FormatHexNumber(offset, offsetSize) ": " } } Else If (Mod(A_Index, 4) = 0) { ; Separate bytes per groups of 4, for readability line := line "| " } dataAddress++ ; Next byte } If (Mod(_byteNb, dumpWidth) != 0) { If (_bExtended) { line := line " - " ascii } dump := dump line "`n" } Return dump }Note it displays 31 00 00 00 because AHK stores integers as Ascii strings.
[EDIT] For a more meaningful result:
VarSetCapacity(buf, 4, 0)
DllCall("RtlFillMemory", "UInt", &buf, "UInt", 1, "UChar", 1)
MsgBox % DumpDWORDs(buf, 4)
I might be wrong but I think shimanov (btw. is he still with us?)
I've been wondering that too?
Hi.
olfen wrote:Interesting.WinHex helped me get started with DllCalls and I am still using it to see what actually is happening in the process memory.
It allows you to open the memory of your running ahk script (Alt-F9) and see what data is present at a certain offset (you can get that offset by evaluating &variable).
I downloaded WinHex.
Could you give some more details about how evaluating &variable?
Thanks
Noel
Here's an example to demonstrate it:
var = 1234567890 ;copy variables address to clipboard setformat, integer, hex offset := &var stringtrimleft, offset, offset, 2 ;remove 0x for WinHex clipboard = %offset% setformat, integer, dec process, exist msgbox, ( Content: %var% Offset: 0x%offset% Now start Winhex and go through the following steps: - Menu: Tools -> Open RAM (Alt+F9) - Double click "Autohotkey #%errorlevel%" - Select "Entire Memory" and click OK - Menu: Postition -> Go To Offset (Alt+G) - Paste the Offset of the variable (it has already been copied to the clipboard) and click OK )
I seriously don't get this dllcalls, it's so confusing :? .
I took a simple example from a help file and modified it a bit but i don't get the desired result for some reason.
DllCall("MessageBox", "int", "0", "str", "example", "str", "My First DllCall", "Uint", "MB_YESNO") return1) according to http://msdn2.microso...y/ms645505.aspx last parameter is Type, but why do i get just an OK button when i specified YES/NO ?
2) What does Unsigned means ?
3)This is from the first page:
DllCall("kernel32.dll\GlobalMemoryStatus" ,"uint",&memoryusage ,"uint",&availphys ,"unit",&totalpagefile) msgbox % &memoryusage msgbox % &availphys msgbox % &totalpagefileWere "availphys" & "memoryusage" came from ??? I'm looking on this page http://msdn2.microso...y/Aa366586.aspx and i can't see this parameters :shock: .
harness the power of extending ahk w/ dllcalls. An example function is
EM_GETSELTEXT.
I am obviously missing some fundamental points on how to get message ID'sThe EM_GETSELTEXT message retrieves the currently selected text in a rich edit control.
lResult = SendMessage( // returns LRESULT in lResult
(HWND) hWndControl, // handle to destination control
(UINT) EM_GETSELTEXT, // message ID
(WPARAM) wParam, // = (WPARAM) () wParam;
(LPARAM) lParam // = (LPARAM) () lParam; );
Parameters
wParam
This parameter is not used; it must be zero. lParam
Pointer to a buffer that receives the selected text. The calling application must
ensure that the buffer is large enough to hold the selected text.
Return Value
This message returns the number of characters copied, not including the
terminating null character.
DllCall("SendMessage" , "UInt", _ctrlID , "UInt", ??? , "Str", "" , "Cdecl Str", &_tmp1)An example function that he already included was for setting EM_SETTEXTEX.
DllCall("SendMessage" , "UInt", _ctrlID , "UInt", 0x461 , "Str", "" , "Str", opt1) ; EM_SETTEXTEXUnless its listed in list of windows messages (in help file..) how is everybody finding these values.? :? Lately there have been tons of new functionality enhancing scripts posted.. & many of the new functions declare these constants included prior to starting function
WS_CHILD := 0x40000000 WS_VISIBLE := 0x10000000 WS_EX_CLIENTEDGE := 0x200 GWL_HINSTANCE := -6 WM_USER := 0x400Besides using one of the mentioned utilities/api databases.. is there something simple like I am overlooking for getting these messages (like a simple function.. or maybe converting EM_GETSELTEXT to hex..?)
I appriciate any help anyone can give.. & I apologize if this has been covered over & over again-- but there are just too many search results to look through when your not evan completely sure what your looking for
Why do you ask that? I saw nobody screaming on you.Is it forbitten to talk about Dlls or something?
Note that most people aren't present 24h a day on the forum, and lot of them are on a different time zone...
After "Int", you have to put an integer, so that's 0, not "0". It might make no difference for AHK, but it is cleaner this way.DllCall("MessageBox", "int", "0", "str", "example", "str", "My First DllCall", "Uint", "MB_YESNO")
"MB_YESNO" isn't correct, see this as a variable holding an integer ("UInt"). To have the values of such variables (actually constants, they never change), a tool like ApiViewer is precious.
It shows Const MB_YESNO As Long = &H4&, which is VB code, but can be translated as MB_YESNO := 0x4
An unsigned number is a number (usually integer) without sign symbol, meaning it is always a positive (or null) number.
They are just variables of the script. The & means to provide their address instead of their values, usually because the API function will fill them (or they are binary structure, ie. complex data).Were "availphys" & "memoryusage" came from
Note that using DllCall without knowing C programming nor Windows programming is at best hazardous, unless you are sticking to using examples found on the forum.
Now, it is doable, Skan managed to use it quite efficiently without prior knowledge.
Daniel2, corrupt prefers to use DllCall to SendMessage, but you can stick to the standard command.
Oh, and the tip on ApiViewer answers your question "how is everybody finding these values.?", another possibility is to download some Windows development tool and look at the provided .h files... But ApiViewer is fast and handy.
Thanks a lot on your tips!
OK i give HowIt shows Const MB_YESNO As Long = &H4&, which is VB code, but can be translated as MB_YESNO := 0x4
WIN or LEARN.
Not sure what your asking... Do you mean "How is 'Const MB_YESNO As Long = &H4&' translated as 'MB_YESNO := 0x4'?"OK i give How