Happy New year everyone!
How would I call a directx function in asm since it needs a C++ object? I supose the object is just structure in memory but I don't know what I would do. In the ddraw.inc file that comes with masm32 there dosen't seam to be much in it I thought there would be a lot more?
Posted on 2002-01-01 18:39:20 by Quantum

normally thats Ernie's playground. ;-)
But I guess I've got what you want.
Check this out:

hDDraw: dd 0

szDDraw: db 'ddraw.dll', 0
szDCreate: db 'DirectDrawCreate', 0

; -- open ddraw.dll --

push offset szDDraw
call LoadLibrary
mov hmodDDraw, eax
test eax, eax
je iveError

; -- get normal API entry --

push offset szDCreate
push hmodDDraw
call GetProcAddress
mov lpfnCreate, eax
test eax, eax
je iveError

; -- create direct draw object --

xor eax, eax
push eax
push offset hDDraw
push eax
call lpfnCreate
test eax, eax
jne iveError

; -- call method ::SetCooperativeLevel()

xor eax, eax
push eax

mov eax, hDDraw
mov eax, [eax]
push hDDraw
call idd_SetCooperativeLevel[eax]
test eax, eax
jne iveError

Ok, here we go.
There are two pushes for both params of SetCooperativeLevel() the third push is the object itselve. idd_SetCooperativeLevel is a simple offset in a table of function pointers. Check out ddraw.inc for the correct offset.

Hafe vun
Bye Miracle
Posted on 2002-01-02 04:22:00 by miracle
This is one way of doing it you can also:


EXTRN DirectDrawCreate:PROC

as an external procedure

and then link your proggy with "ddraw.lib"

also after you understand how a DirectX COM call is done you can start to use DDinvoke macros to make your life easy
Posted on 2002-01-02 18:50:47 by BogdanOntanu
Are the ddinvoke matrcos included in masm32 allready?
Posted on 2002-01-02 20:08:01 by Quantum
Ok ok... To answer this question properly:

What version of DirectX are you using?

If you want to use 8.0 or 8.1 you can uses Scronty's website as an example of using "mcall" (he has various examples and tutorials from the sdk)

or coinvoke is used by Caleb (a very nice looking demo he wrote for directx 8.0)

(both names can be searched in the member directory and both have all the includes)

If you are using lesser versions (because you want to have a pointer to video member (all you really lose from 7.0 to 8.0) you can find

Chris Hobbs example of using directx (4.0) enlightening (can be found on gamedev.net -- search with "win32asm"

If your using 7.0 I have a source and some includes you maybe able to use



DDINVOKE MACRO func, this, arglist :VARARG
mov eax , [this]
mov eax , [eax]

IFB <arglist>
INVOKE [IDirectDrawVtbl. func][eax], this
INVOKE [IDirectDrawVtbl. func][eax], this, arglist

example of use:

; Initialize display

INVOKE DirectDrawCreate, NULL, ADDR lpDD, NULL
.IF eax != DD_OK
FATAL "Couldn't init DirectDraw"

.IF eax != DD_OK
FATAL "Couldn't set DirectDraw cooperative level"

DDINVOKE SetDisplayMode, lpDD, ddwidth, ddheight, ddbpp
.IF eax != DD_OK
FATAL "Couldn't set display mode"
Posted on 2002-01-02 21:50:20 by Sliver
I want to use directx 8.1 I've heard that the api is simpler in the later version, dose anyone know if this is tru?
Posted on 2002-01-03 01:27:56 by Quantum
It really depends on what you mean by, "more easy to use". It is more powerful, IMHO. But you may have to judge for yourself... He converted all the m$ tutorials to assembly.

Go here and see for yourself:

Scronty's Direct 8.0 and 8.1 win32asm page

Posted on 2002-01-03 23:01:31 by Sliver