The MASM Forum

General => The Workshop => Topic started by: felipe on April 09, 2018, 02:39:56 PM

Title: Help calling a function
Post by: felipe on April 09, 2018, 02:39:56 PM
Here is what i have of the include file for d3d9.lib.:

;CONSTANTS:
D3D_SDK_VERSION     equ     32
D3DADAPTER_DEFAULT  equ     0
D3DDEVTYPE_HAL      equ     1
D3DCREATE_SOFTWARE_VERTEXPROCESSING    equ 00000020h


;FUNCTIONS:
Direct3DCreate9     proto    :dword
CreateDevice     proto    :dword,:dword,:dword,:dword,:dword,:dword


If in a program (where i include this file and the d3d9.lib and boths are in the masm32 inc and lib folders) i call the first function (Direct3DCreate9) every go ok. But when i use the second (CreateDevice) i have this link error:

Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

clicklaugh.obj : error LNK2001: unresolved external symbol _CreateDevice@24
clicklaugh.exe : fatal error LNK1120: 1 unresolved externals
_
Link error
...

How i should write the name of this function in the include file? How is the syntax of this convention? Any help will be great appreciated. Actually doing this (sh*t) job is frustrating if you don't know how to. I wish to be coding already... :(
Title: Re: Help calling a function
Post by: Lonewolff on April 09, 2018, 02:48:00 PM
Can you also show the code you are using to create the device?

You are linking to D3D9.lib also?


**Edit**

Actually CreateDevice is not a function as such, it is a member of the IDirect3D9 interface (setup in the vTable).

So you don't need the function prototype at all.

You need to be using 'coinvoke' for the call.
Title: Re: Help calling a function
Post by: felipe on April 09, 2018, 03:13:44 PM
Quote from: Lonewolff on April 09, 2018, 02:48:00 PM
Can you also show the code you are using to create the device?
Is just  simple code with the appropiate includes and includelib and the call instructions (nothing to worry about is just for testing the include file).

Quote from: Lonewolff on April 09, 2018, 02:48:00 PM
You are linking to D3D9.lib also?
Yes

Quote from: Lonewolff on April 09, 2018, 02:48:00 PM
**Edit**

Actually CreateDevice is not a function as such, it is a member of the IDirect3D9 interface (setup in the vTable).

So you don't need the function prototype at all.

You need to be using 'coinvoke' for the call.

And what is coinvoke or where is defined?

Thanks for the help.
Title: Re: Help calling a function
Post by: Lonewolff on April 09, 2018, 03:18:08 PM
It is defined in the d3d9macro.inc file (assuming you are using Siekmanski's libraries).

Your CreateDevice command should look along the lines of this


coinvoke d3dDevice, IDirect3D9, param1, 2, 3, etc...


Title: Re: Help calling a function
Post by: felipe on April 09, 2018, 03:52:16 PM
Ok, thanks for your help.
Title: Re: Help calling a function
Post by: Lonewolff on April 09, 2018, 03:53:28 PM
No probs :)

Did you get it going?
Title: Re: Help calling a function
Post by: felipe on April 10, 2018, 10:19:35 AM
No. I actually don't like macros too much. I will keep trying others ways. If anybody can say something relative with the decoration notation from the include file or from the source code where it call these functions, thank you very much.  :icon14:
Title: Re: Help calling a function
Post by: Fabioxds on April 11, 2018, 11:47:08 PM
Did you try to use the macro then take a look at the generated code? I always do that to steal assembly code or to learn how things are being done under the hood  :bgrin:
Title: Re: Help calling a function
Post by: Lonewolff on April 12, 2018, 07:13:57 AM
Giving up is always easier  :bgrin:
Title: Re: Help calling a function
Post by: zedd151 on April 12, 2018, 07:36:14 AM
Quote from: Lonewolff on April 12, 2018, 07:13:57 AM
Giving up is always easier  :bgrin:

winners never quit,   :eusa_naughty:

and quitters never win.   :eusa_snooty:

stole line from rrr314..... cant remember what comes next for pi.  :P
Title: Re: Help calling a function
Post by: Lonewolff on April 12, 2018, 07:37:40 AM
Very true though.  :t
Title: Re: Help calling a function
Post by: felipe on April 12, 2018, 09:21:52 AM
 :biggrin: Sometimes the winners are not the pretty guys of the movies, i'm very happy with the assembly language even if microsh*t don't like to support it. :biggrin:
Title: Re: Help calling a function
Post by: Lonewolff on April 12, 2018, 09:42:32 AM
Quote from: felipe on April 12, 2018, 09:21:52 AM
:biggrin: Sometimes the winners are not the pretty guys of the movies, i'm very happy with the assembly language even if microsh*t don't like to support it. :biggrin:

In what way do you mean? DirectX?

They do support it though. That is why DirectX is written in COM, to make it language independent.
Title: Re: Help calling a function
Post by: felipe on April 12, 2018, 09:46:43 AM
Yes sure, is this a c forum btw?  :idea:
Title: Re: Help calling a function
Post by: Lonewolff on April 12, 2018, 09:47:39 AM
Quote from: felipe on April 12, 2018, 09:46:43 AM
is this a c forum btw?  :idea:

Not sure what you mean by this.
Title: Re: Help calling a function
Post by: aw27 on April 13, 2018, 05:07:09 PM
In ASM, dealing with COM, and in particular with DirectX, is not easy without macros.
Since I don't like macros as well, I very rarely try to do it in ASM.
UASM has a nice framework for that, I tried it and helped fix bugs, however the philosophy is the same - obfuscate the complexity - which in my opinion is against the spirit of ASM.
Better we use a high-level language if we don't care about the nittty gritties.
Title: Re: Help calling a function
Post by: hutch-- on April 18, 2018, 12:03:16 AM
Guys,

I think tastes in coding design are many and having to deal with high level structures is simply part of writing 32 and 64 bit assembler and generally the documentation for any Windows version is written in C so we also have to translate this to a MASM format, something that folks who have worked in MASM for any length of time are experienced at doing.

As far as using macros, some prefer to do all of their coding in raw mnemonics and in fact this is probably the best technique for high performance algorithms but there is a vast amount of Windows code where there is no advantage at all manually coding stuff that is finally just hack OS code so using macros in this context makes sense to end up with clear coding of what is often messy OS code.

This much I would ask of all of our more experienced members, remember how hard it was when we all started years ago and give folks who are starting to write this style of code a fair go.