can't figure out why getting this error

as you can see the typedef of ord to DWORD takes

the struct is in
x word ?
y word ?

: error A2114: INVOKE argument type mismatch : argument : 3

;BOOL ReadConsoleOutput(
; HANDLE hConsoleOutput, // handle of a console screen buffer
; PCHAR_INFO lpBuffer, // address of buffer that receives data
; COORD dwBufferSize, // column-row size of destination buffer
; COORD dwBufferCoord, // upper-left cell to write to
; PSMALL_RECT lpReadRegion // address of rectangle to read from

invoke ReadConsoleOutput,hmystdout, addr buffer, sz ,ord, addr smRect

Posted on 2003-01-08 19:26:47 by RockyJ
I guess the proto only allows DWORD

Any way to typedef to a DWORD or equ it.
Posted on 2003-01-08 19:32:30 by RockyJ

invoke ReadConsoleOutput,hmystdout, addr buffer, addr sz ,addr ord, addr smRect

Struct are accessed by pointers.
Posted on 2003-01-09 04:33:09 by roticv
i dont think that function expects a pointer for arguments 3 and 4, since the coord structure is 32 bits, its more efficient just to push a dword onto the stack... there is probably a better way to do this but here is a temp fix...


; copy sz.x and sz.y to edx (cant use eax because of invoke conflicts)
mov dx, sz.x
shl edx, 16
mov dx, sz.y
; copy ord.x and ord.y to ecx
mov cx, ord.x
shl ecx, 16
mov cx, ord.y
; use ecx and edx instead of structs
invoke ReadConsoleOutput,hmystdout, addr buffer, edx , ecx, addr smRect

if I were using C i could always use the helpful cast method, but I have never seen this done in masm... maybe this prototype needs to be modified to work correctly? I have no idea... :confused:
Posted on 2003-01-09 05:05:06 by BubbaFate
Bubba, thats the way I coded it or similar, but as far as a new prototype I haven't tried changing the windows. inc.

Also I don't know how to state an immediate in a typed form like:

invoke somefunctionneedingCoord, COORD <80,160>

instead of somefunctionneedingCoord, 005000A0h
Posted on 2003-01-09 17:50:49 by RockyJ
Originally posted by RockyJ
Also I don't know how to state an immediate in a typed form like:
invoke somefunctionneedingCoord, COORD <80,160>

I don't think you can. You can use this though:
invoke func, 80 OR (160 SHL 16)

Posted on 2003-01-11 04:09:31 by Thomas
Problem 1)

My has:

x WORD ?
y WORD ?

Yours is something that im surprised will comiple with out error...

Problem 2)
Struct are accessed by pointers.

This is correct, but does not (and should not) imply you have to pass pointers in function calls. Its only more efficient to do so, but does not mean its a limitation!!

Problem 3)

BubbaFate is 100% correct in his solution. The problem IS the fact that there is not a pointer required since the struct is 32 bits anyways (in this case its not efficient for the API). Instead of changing your Kernel32 and making your source different from the 'standard' that Hutch and Iczelion has prepared for us a solution is using macros:

LOCAL outstring
IF (OPATTR (areg)) AND 00000100y ;; If an immediate Value
outstring TEXTEQU <&areg OR ( &MemAddr SHL 16 )>
lea eax , MemAddr
mov areg, [eax]
outstring TEXTEQU <&areg>
EXITM <&outstring>

lala COORD <>
invoke ReadConsoleOutput,NULL, NULL, Cast2DWORD(edx,lala), Cast2DWORD(1,2), NULL
00401FFD >/$ 8D05 08384000  LEA EAX,DWORD PTR DS:[403808]

00402003 |. 8B10 MOV EDX,DWORD PTR DS:[EAX]
00402005 |. 6A 00 PUSH 0 ; /pSourceRect = NULL
00402007 |. 68 01000200 PUSH 20001 ; |DestBufferCoord = (X=1.,Y=2.)
0040200C |. 52 PUSH EDX ; |DestBufferSize
0040200D |. 6A 00 PUSH 0 ; |DestBuffer = NULL
0040200F |. 6A 00 PUSH 0 ; |hConsole = NULL
00402011 |. E8 3A010000 CALL <JMP.&KERNEL32.ReadConsoleOutputA> ; \ReadConsoleOutputA

It works by looking at the first param. If its a register, it uses memory access to get the coord (or any 32 bit value from memory). If its a litteral value, it assumes your building a DWORD and builds the litteral value as Thomas pointed out.

This macro can be used for other purposes as well, like making WM_COMMAND params. Something that comes to mind is the CombBox messages:
"invoke SendMessage, hWindow, WM_COMMAND, Cast2DWORD( CB_ID_NUM, CB_SELCHANGE ), lParam".

Anywho.. Enjoy.
Posted on 2003-01-11 15:00:10 by NaN