Trouble with DllStructAlloc

Started by kdmoyers, November 16, 2020, 01:14:40 PM

Previous topic - Next topic

kdmoyers

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?
Code (winbatch) Select
    ;    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)
The mind is everything; What you think, you become.

td

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
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

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 mind is everything; What you think, you become.

td

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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade