Don't ask why I'm looking at this now, but,
I can't see what I'm doing wrong here. I get 1378 DllCall Bad Parm Code
I can't find an example of DllStruct actually being used in a call, but this is my best guess.
Can anyone tell me what's wrong?
; int MessageBoxA(
; HWND hWnd,
; LPCSTR lpText,
; LPCSTR lpCaption,
; UINT uType
; );
;
; from https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messageboxa
;
user32 = DirWindows(1) : "user32.DLL"
caption = "attention!"
text = "hello there"
wtype = 48
myself = DllHwnd("")
descriptor = "hwnd:winhandle lpcstr:text lpcstr:caption uint:control"
structhand = DllStructAlloc( descriptor )
dllstructpoke(structhand, "winhandle", myself )
dllstructpoke(structhand, "text", text )
dllstructpoke(structhand, "caption", caption )
dllstructpoke(structhand, "winhandle", wtype )
xx = DllCall(user32, long:"MessageBoxA", structhand)
dllstructfree(structhand)
Yikes!? DllStructAlloc and friends are intended for use in calls into C based DLL export functions when those functions expect a pointer to a C data structure known as a "struct" in the C language parlance. Or as the help file describes it, "The returned handle can be used with DllCall or DllCallCdecl when calling an external DLL entry point that requires the memory address of a C/C++ language style structure as a parameter."
The MessageBox Win32 function does not take a pointer to a structure as a parameter so you can't use a DllStructAlloc created structure when calling the function.
There are several examples of using DllStructAlloc on the forum. Here is a link to one of them:
https://forum.winbatch.com/index.php?topic=2397.msg12697#msg12697 (https://forum.winbatch.com/index.php?topic=2397.msg12697#msg12697)
Got it. Makes sense, thanks Tony!
BTW, when I type DllStructAlloc into the tech database search, it comes up "Sorry, no items matching". How did you find that example?
-Kirby
The example is from this forum and not the Tech Database. It does seem a bit odd that there are no examples in the Tech Database though. We will have to do something about that when time permits.
Here is a new Tech Database DllStructAlloc example:
https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/DllCall~Information+DllStructAlloc~Example.txt (https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/DllCall~Information+DllStructAlloc~Example.txt)