News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

COM & DirectX (Easy and clean)

Started by Ariel, December 19, 2005, 04:41:44 AM

Previous topic - Next topic

Ariel

Hello everyone.
I've been programming in DirectX and i have made a few macros that can be useful for using COM. It is basically a modification of the macros that are allredy included in the MASM32 Pack.
The first macro is COM and it is used to declare the COM variable
The second is LCOM and it is similar to COM but it is used to declare LOCAL variables inside PROCs
The third one, cinvoke, is use to invoke the interfaces of the COM.

Exaple of usage:
.386
.model flat, strcall
    ...
Some includes
    ...
.DATA
   COM g_pD3D, IDirect3D9
        COM g_pd3dDevice, IDirect3D9Device
   ...
.CODE
  ...
       ; Get the COM object
       invoke            Direct3DCreate9, D3D_SDK_VERSION
       mov      g_pD3D, eax
...
      ; Create the device
   cinvoke   g_pD3D, CreateDevice, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWin, \
                          D3DCREATE_HARDWARE_VERTEXPROCESSING, \
                          addr d3dpp, addr g_pd3dDevice
...
      ; Release the object
       cinvoke         g_pD3D, Release
...

In that little explample you can notice that the syntax is very similar to C and it is very easy to use DirectX.

There are also some other useful macros, you can find more help readin COM.INC and in the examples

About DirectX

When i started programming in DirectX i was very excited becouse it seemed to be very easy but then i reached a limitation, DirectX has an extension library that makes some of the most important part of the 3D calculation (like matrix manipulation, meshes control, fonts, etc), the problem is that the library is an Static Link Library and will only compile with C so after some meditation i decided to translare the library but, in a second thounght, i realized that there was a better solution, to create a Dinamic Link Library of the Static Link Library which can be used by any application.
Due to stoarge limitations i can only include here the source code, you need the DirectX SDK and Visual C++ to compile it.
After compilation you have to rename the file to D3DX9.DLL

How to use it:

Just include D3DX9.inc and D3DX9.lib in your project and then make a call to the initialization function in the DLL like:
              invoke   InitDXMath, addr Tabla

How it works

It is easy, the function InitDXMath recives a pointer to an array witch will be filled with the entry point of each of the DirextX Extension functions.

If you have any problems compiling the file you can send me a mail (areynoso@gmail.com)and i will send to you the complied version and if you want more examples and other stuff related to DirectX that can be useful.

In conclusion

Please tell me what you think about this or if you have any coments or questions plase reply this topic
I hope you find this useful :-)

PD: Please forgive my bad english

[attachment deleted by admin]

zooba

Quote from: Ariel on December 19, 2005, 04:41:44 AM
...After compilation you have to rename the file to D3DX9.DLL...

I'm pretty sure there is a D3DX9.DLL that ships with DirectX 9 already. Not sure how it links though. Hitchkr? :bg

JFG

Note:  Ariel, don't worry about your English.  I'm in the U.S., and I must say your written English is definitely far better than what I normally see from my peers around here, including those native to this country.  (They seem to not care at all for grammar, spelling, or punctuation actually.)

Hey, this is really cool!  At least it certainly looks much neater than the other COM macros I've seen.  Do you not get any problems with unresolved external symbols and such when you use this?  I tried working with DirectX COM interfaces using MASM, but got stuck at a problem of unresolved externals at the linking stage, I have no clue why.  I was considering making some kind of DirectX interface DLL using VC++ too, but have not liked the idea because it would add a rather undesirable complication to programs, being that I also want to code stuff in MASM.  Then also, I have had that same sort of annoying unresolved externals problem with VC++ too.  Do know if your macros dodge the cause of that unresolved externals problem?

shaldan

JFG: I got the same problems and solved it simply by include all lib in lib directory and suddenly a miracle happened: IT WORKED :)).
But i do not code DirectX meanwhile and I just wanted to compile and link some DirectX examples just for curiosity... :)

zooba

Did you try looking up the functions in Hutch's API Library list so you could see exactly which library it's from?

Ariel

zooba: Yes, i tried looking for it anywhere but after long afternoons of serching, i get to the conclusion that the extension library is only for C++ and there is no equivalent or any DLL that you can use in MASM so the only solution to enable MASM to use the original extension library is to create that DLL that i mentioned earlier.

PD: There is only one DLL that can be used and that exports the functions. It is dx8vb.dll but it is for Visual Basic and i don`t think it is as optimized or efficient as the original extension library is; besides it is for DirectX 8.

Szeki

Hi Boys!  ::)

I would like to use DirectX interfaces but I don't know how?

I have Caleb include and libs, but I think it's not completed fully... (DirectX 8.1 for MASM)

Forexample:
- I CALL the DirectDrawCreate and I make a DirectDraw object. It's ok.
- I would like to reach the IDirectDraw2 interface? (forexample SetDisplayMode)

How can I use the QueryInterface method?

I think it's required...

Thank you.

Szeki.    ::)
(my english is not perfect...)

Ariel

Hi everyone, i has been a long time but i am back.

I wrote this 2 tuts some time ago for a friend and I think that they can be useful for somebody else, they are about the essential of COMs and DirectX and how to create macros that can make it easy to work with them.

I think the tuts are clear enough to make anyone port the power of DirectX to any application written in MASM.

If you have any suggestion/question please write to my mail.

Thanks for reading!.


[attachment deleted by admin]