2

I disassemble CreateDevice function from my DirectX code and commented each paratemer:

.text:0043F485                 mov     eax, [ebp+lpParam]
.text:0043F488                 add     eax, 730h
.text:0043F48D                 push    eax  ;LPDIRECT3DDEVICE9
.text:0043F48E                 mov     ecx, [ebp+lpParam]
.text:0043F491                 add     ecx, 0B88h
.text:0043F497                 push    ecx  ;D3DPRESENT_PARAMETERS
.text:0043F498                 mov     edx, [ebp+var_170]
.text:0043F49E                 push    edx  ;vertex processing type
.text:0043F49F                 mov     eax, [ebp+lpParam]
.text:0043F4A2                 mov     ecx, [eax+728h]
.text:0043F4A8                 push    ecx  ;hWnd
.text:0043F4A9                 push    1    ;D3DDEVTYPE_HAL
.text:0043F4AB                 push    0    ;D3DADAPTER_DEFAULT
.text:0043F4AD                 mov     edx, [ebp+lpParam]
.text:0043F4B0                 mov     eax, [edx+734h]
.text:0043F4B6                 mov     ecx, [ebp+lpParam]
.text:0043F4B9                 mov     edx, [ecx+734h]
.text:0043F4BF                 mov     eax, [eax]
.text:0043F4C1                 push    edx  ;??????????????
.text:0043F4C2                 mov     ecx, [eax+40h]   ;this pointer
.text:0043F4C5                 call    ecx  ;call CreateDevice
.text:0043F4C7                 mov     eax, [ebp+lpParam]
.text:0043F4CA                 mov     ecx, [eax+730h];LPDIRECT3DDEVICE9 in return

Using experimental way I figured out LPDIRECT3DDEVICE9 variable presents in:

.text:0043F48D                 push    eax  ;LPDIRECT3DDEVICE9

Also, using debugger I figured out edx register:

.text:0043F4C1                 push    edx  ;??????????????

has value d3d9.dll:6521F191 db 0B8h what in expand view is:

d3d9.dll:6521F191 db 0B8h ; ¬
d3d9.dll:6521F192 db  48h ; H
d3d9.dll:6521F193 db  77h ; w
d3d9.dll:6521F194 db  23h ; #

My question, why before CreateDevice function calling is there "push edx" line of code? In my example I used OOP and ecx is this pointer:

.text:0043F4C2                 mov     ecx, [eax+40h]   ;this pointer

But what purpose is this line of code:

.text:0043F4C1                 push    edx  ;d3d9.dll:6521F191 db 0B8h ; ¬

Is it like this pointer for DirectX COM interface or what?

Thanks in advance!

1 Answer 1

2

DirectX interfaces like IDirect3D9/IDirect3DDevice9 are COM interfaces and not C++ classes.

COM (OLE2) predates the wide use of C++ and uses a C-compatible calling convention, __stdcall, instead of the C++specific __thiscall. The use of ecx is a red herring; here it's used to load the function pointer (IDirect3D9::CreateDevice) and jump to it, not as the this pointer. The first argument to the call (push edx) is the This pointer (the interface itself).

In C syntax, the call would look like this:

IDirect3D9 *d3d = Direct3DCreate9(D3D_SDK_VERSION);
IDirect3DDevice9 *pDevice;
d3d->lpVtbl->CreateDevice(d3d, adapter, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, BehaviorFlags, &presentationParameters, &pDevice);

All arguments to CreateDevice are pushed on the stack according to the __stdcall convention.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.