Sign in to follow this  
Followers 0
monoceres

IUnknown Interface & Direct3D

12 posts in this topic

So, I'm completely lost here. I've worked with Direct3D lately and I remember reading that it was COM based so I thought, Ok, maybe I can communicate with it directly using AutoIt.

Apparently you have to create the objects through the IUnknown interface or something. I read about it and it seems that all Interfaces have to support it and you have to use the QueryInterface method to create the d3d objects or something. As you can imagine I'm totally lost here.

I tried looking up the d3d header file but, well it confused me even more.

Like this (Declaration of IDirect3D):

DECLARE_INTERFACE_(IDirect3D9, IUnknown)

// A lot of method prototypes

Any ideas, or should I just drop this and implement it in a plugin instead?


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites



So, I'm completely lost here. I've worked with Direct3D lately and I remember reading that it was COM based so I thought, Ok, maybe I can communicate with it directly using AutoIt.

Apparently you have to create the objects through the IUnknown interface or something. I read about it and it seems that all Interfaces have to support it and you have to use the QueryInterface method to create the d3d objects or something. As you can imagine I'm totally lost here.

I tried looking up the d3d header file but, well it confused me even more.

Like this (Declaration of IDirect3D):

DECLARE_INTERFACE_(IDirect3D9, IUnknown)

// A lot of method prototypes

Any ideas, or should I just drop this and implement it in a plugin instead?

I know nothing about Direct3D but I've done a little COM .. mostly Shell Extensions. afaik interpreted languages require the COM server it wants to use to have the IDispatch interface. All COM servers have IUnknown but not all have IDispatch. Wading through COM macros I'd say is a waste of time unless you absolutely have to do it for work, or have masochistic tendencies. Since marcros are text substitution my experience when trying to alter them to my purpose usually resulted in getting 98% of the way there, then hitting a wall because there are only so many things that can survive being substituted all the way down through the chain of macros and still compile.

Short answer: find out for sure if there's an IDispatch interface. If not, use a compiled code type of client to get at the IUnknown based interfaces. The IUnknown interface is very much like a C++ virtual method jump table. With IDispatch there's a mechanism to search for the name of the function you are looking for. With IUnknown you have to know the name of the Interface you are searching for and query with QueryInterface. If successful then you get a pointer back that you use in subsequent calls.

It's been a few years since I've read up on this stuff. Just going from memory.. but if the IUnknown interfaces are well documented it's not that hard to initialize and use them.

If you're interested one of those Wrox red COM or ATL books is probably a good place to start.

Delphi 5 made it really easy to convert a TWinControl into a dual interfaced ActiveX Control.

Only trouble is I've never seen a Delphi-based Shell Extension that actually worked as advertised..

For those I had to find a Visual Studio C++ wizard that spit out the code framework. Coding

COM macros by hand? ... not unless there's gun to my head. :mellow:

Share this post


Link to post
Share on other sites

Thanks for your post, unfortunately I don't understand much of it.

I know that this code is bull, but why can't something like this work?

$IUnknown = ObjCreate("IUnknown.IUnknown"); Or whatever to get an IUnknown Interface
$Direct3D9 = $IUnknown.QueryInterface("IDirect3D9")
$Direct3D9.CreateDevice(...

Argh, this is all so confusing.

Oh, and I'm pretty sure the IDirect3D9 interface doesn't support IDispatch, is there any way to test if it does from a valid IDirect3D9 object?


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

It could be possible with MemoryDLL :mellow: like I#ve done it here: http://www.autoitscript.com/forum/index.ph...st&p=599174


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Made a working example (just getting the object and release it :mellow: )

#include "MemoryDLL\MemoryDLL.au3"
DllOpen("d3d9.dll")

; Definitoins from http://source.winehq.org/source/include/d3d9.h
#cs D3D9-EX-Interface
DECLARE_INTERFACE_(IDirect3D9Ex,IDirect3D9)
    /*** IUnknown methods ***/
    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
    STDMETHOD_(ULONG,Release)(THIS) PURE;
    /*** IDirect3D9 methods ***/
    STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction) PURE;
    STDMETHOD_(UINT, GetAdapterCount)(THIS) PURE;
    STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) PURE;
    STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter, D3DFORMAT Format) PURE;
    STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) PURE;
    STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter, D3DDISPLAYMODE* pMode) PURE;
    STDMETHOD(CheckDeviceType)(THIS_ UINT iAdapter, D3DDEVTYPE DevType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed) PURE;
    STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) PURE;
    STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) PURE;
    STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) PURE;
    STDMETHOD(CheckDeviceFormatConversion)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) PURE;
    STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) PURE;
    STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter) PURE;
    STDMETHOD(CreateDevice)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, struct IDirect3DDevice9** ppReturnedDeviceInterface) PURE;
    /*** IDirect3D9Ex methods ***/
    STDMETHOD_(UINT, GetAdapterModeCountEx)(THIS_ UINT Adapter, CONST D3DDISPLAYMODEFILTER *pFilter) PURE;
    STDMETHOD(EnumAdapterModesEx)(THIS_ UINT Adapter, CONST D3DDISPLAYMODEFILTER *pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode) PURE;
    STDMETHOD(GetAdapterDisplayModeEx)(THIS_ UINT Adapter, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation);
    STDMETHOD(CreateDeviceEx)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode, struct IDirect3DDevice9Ex **ppReturnedDeviceInterface) PURE;
    STDMETHOD(GetAdapterLUID)(THIS_ UINT Adatper, LUID *pLUID) PURE;
};
#ce
Global Const $IUnknown_vTable = "ptr QueryInterface; ptr AddRef; ptr Release;"
Global Const $IDirect3D9_vTable = $IUnknown_vTable & "ptr RegisterSoftwareDevice; ptr GetAdapterCount; ptr GetAdapterIdentifier; ptr GetAdapterModeCount; " & _
        "ptr EnumAdapterModes; ptr GetAdapterDisplayMode; ptr CheckDeviceType; ptr CheckDeviceFormat; ptr CheckDeviceMultiSampleType; ptr CheckDepthStencilMatch; " & _
        "ptr CheckDeviceFormatConversion; ptr GetDeviceCaps; ptr GetAdapterMonitor; ptr CreateDevice;"
Global Const $IDirect3D9Ex_vTable = $IDirect3D9_vTable & "ptr GetAdapterModeCountEx; ptr EnumAdapterModesEx; ptr GetAdapterDisplayModeEx; ptr CreateDeviceEx; GetAdapterLUID;"

Global Const $IUnknown = "ptr IUnknown;"
Global Const $IDirect3D9 = "ptr IDirect3D9;"

Global COnst $D3D_SDK_VERSION = 32

$D3D9_Pointer = DllCall("d3d9.dll","ptr","Direct3DCreate9","uint",$D3D_SDK_VERSION)
If @error Or $D3D9_Pointer[0]=0 Then Exit
$D3D9_Pointer = $D3D9_Pointer[0]
MsgBox(0, '', $D3D9_Pointer)
$D3D9_Interface = DllStructCreate($IDirect3D9,$D3D9_Pointer)
$D3D9_FuncPointers = DllStructCreate($IDirect3D9_vTable,DllStructGetData($D3D9_Interface,1))

$Func_Release = DllStructGetData($D3D9_FuncPointers,"Release")

MemoryFuncCall("dword",$Func_Release,"ptr",$D3D9_Pointer)
MsgBox(0, '', @error)
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

I love you ProgAndy :mellow:

Now I'm off to create an D3D UDF :(


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Continued a bit, because I wanted to check a window with D3D output ;) ( made examples for UDF creation, too)

#include "MemoryDLL\MemoryDLL.au3"
#include<Timers.au3>
DllOpen("d3d9.dll")
DllOpen("D3DX9_39.dll")
; Definitions from:
; --> http://source.winehq.org/source/include/d3d8types.h
; --> http://source.winehq.org/source/include/d3d9.h
; --> freebasic: d3d9.bi, d3d9types.bi, d3d9caps.bi
; --> http://www.math.uni-leipzig.de/pool/tuts/SelfDXD/DirectXGraphics/dg.html
; --> MSDN :P

Func MAKE_HRESULT($sev,$fac,$code)
    Return BitOR(BitShift($sev,-31) , BitOR(BitShift($fac,-16),  $code))
EndFunc
Func MAKE_D3DSTATUS($code)
    Return MAKE_HRESULT(0,0x876,$code)
EndFunc
Func MAKE_D3DHRESULT($code)
    Return MAKE_HRESULT(1,0x876,$code)
EndFunc

Global COnst $D3D_SDK_VERSION = 32

Global Const $D3DCREATE_FPU_PRESERVE = 0x02
Global Const $D3DCREATE_MULTITHREADED = 0x04
Global Const $D3DCREATE_PUREDEVICE = 0x10
Global Const $D3DCREATE_SOFTWARE_VERTEXPROCESSING = 0x20
Global Const $D3DCREATE_HARDWARE_VERTEXPROCESSING = 0x40
Global Const $D3DCREATE_MIXED_VERTEXPROCESSING = 0x80

Global Const $D3DSPD_IUNKNOWN = 1
Global Const $D3DSGR_NO_CALIBRATION = 0
Global Const $D3DSGR_CALIBRATE = 1
Global Const $D3D_OK = 0
Global Const $D3DOK_NOAUTOGEN   = MAKE_D3DSTATUS(2159)
Global Const $D3DERR_WRONGTEXTUREFORMAT = MAKE_D3DHRESULT(2072)
Global Const $D3DERR_UNSUPPORTEDCOLOROPERATION  = MAKE_D3DHRESULT(2073)
Global Const $D3DERR_UNSUPPORTEDCOLORARG    = MAKE_D3DHRESULT(2074)
Global Const $D3DERR_UNSUPPORTEDALPHAOPERATION  = MAKE_D3DHRESULT(2075)
Global Const $D3DERR_UNSUPPORTEDALPHAARG    = MAKE_D3DHRESULT(2076)
Global Const $D3DERR_TOOMANYOPERATIONS  = MAKE_D3DHRESULT(2077)
Global Const $D3DERR_CONFLICTINGTEXTUREFILTER   = MAKE_D3DHRESULT(2078)
Global Const $D3DERR_UNSUPPORTEDFACTORVALUE = MAKE_D3DHRESULT(2079)
Global Const $D3DERR_CONFLICTINGRENDERSTATE = MAKE_D3DHRESULT(2081)
Global Const $D3DERR_UNSUPPORTEDTEXTUREFILTER   = MAKE_D3DHRESULT(2082)
Global Const $D3DERR_CONFLICTINGTEXTUREPALETTE  = MAKE_D3DHRESULT(2086)
Global Const $D3DERR_DRIVERINTERNALERROR    = MAKE_D3DHRESULT(2087)
Global Const $D3DERR_NOTFOUND   = MAKE_D3DHRESULT(2150)
Global Const $D3DERR_MOREDATA   = MAKE_D3DHRESULT(2151)
Global Const $D3DERR_DEVICELOST = MAKE_D3DHRESULT(2152)
Global Const $D3DERR_DEVICENOTRESET = MAKE_D3DHRESULT(2153)
Global Const $D3DERR_NOTAVAILABLE   = MAKE_D3DHRESULT(2154)
Global Const $D3DERR_OUTOFVIDEOMEMORY   = MAKE_D3DHRESULT(380)
Global Const $D3DERR_INVALIDDEVICE  = MAKE_D3DHRESULT(2155)
Global Const $D3DERR_INVALIDCALL    = MAKE_D3DHRESULT(2156)
Global Const $D3DERR_DRIVERINVALIDCALL  = MAKE_D3DHRESULT(2157)
Global Const $D3DERR_WASSTILLDRAWING    = MAKE_D3DHRESULT(540)
Global Const $D3DADAPTER_DEFAULT = 0
Global Const $D3DCURSOR_IMMEDIATE_UPDATE = 1
Global Const $D3DENUM_HOST_ADAPTER = 1
Global Const $D3DENUM_NO_WHQL_LEVEL = 2
Global Const $D3DPRESENT_BACK_BUFFERS_MAX = 3
Global Const $VALID_D3DENUM_FLAGS = 3
Global Const $D3DMAXNUMPRIMITIVES = 0xFFFF
Global Const $D3DMAXNUMVERTICES = 0xFFFF
Global Const $D3DCURRENT_DISPLAY_MODE = 0xEFFFFF

Global COnst $D3DDEVTYPE_HAL      = 1
Global COnst $D3DDEVTYPE_REF       = 2
Global COnst $D3DDEVTYPE_SW        = 3

Global Const $D3DADPATER_DEFAULT = 0


Global Const $D3DRECT = "long x1; long y1; long x2; long y2;"

Global Const $D3DPRESENT_PARAMETERS = _
    "UINT                    BackBufferWidth;" & _ ; 
    "UINT                    BackBufferHeight;" & _ ; 
    "dword               BackBufferFormat;" & _ ; D3DFORMAT 
    "UINT                    BackBufferCount;" & _ ; 
    "dword     MultiSampleType;" & _ ; D3DMULTISAMPLE_TYPE
    "DWORD                   MultiSampleQuality;" & _ ; 
    "dword           SwapEffect;" & _ ; D3DSWAPEFFECT
    "HWND                    hDeviceWindow;" & _ ; 
    "int                    Windowed;" & _ ; BOOL
    "int                    EnableAutoDepthStencil;" & _ ; BOOL
    "dword               AutoDepthStencilFormat;" & _ ; D3DFORMAT
    "DWORD                   Flags;" & _ ; 
    "UINT                    FullScreenRefreshRateInHz;" & _ ; 
    "UINT                    PresentationInterval;"

; The IUnknown-Interface
Global Const $IUnknown_vTable = "ptr QueryInterface; ptr AddRef; ptr Release;"
Global Const $IUnknown = "ptr IUnknown;"

#Region IDirect3D9Ex and IDirect3D9 Interfaces
#cs D3D9-EX-Interface
DECLARE_INTERFACE_(IDirect3D9Ex,IDirect3D9)
    /*** IUnknown methods ***/
    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
    STDMETHOD_(ULONG,Release)(THIS) PURE;
    /*** IDirect3D9 methods ***/
    STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction) PURE;
    STDMETHOD_(UINT, GetAdapterCount)(THIS) PURE;
    STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) PURE;
    STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter, D3DFORMAT Format) PURE;
    STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) PURE;
    STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter, D3DDISPLAYMODE* pMode) PURE;
    STDMETHOD(CheckDeviceType)(THIS_ UINT iAdapter, D3DDEVTYPE DevType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed) PURE;
    STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) PURE;
    STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) PURE;
    STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) PURE;
    STDMETHOD(CheckDeviceFormatConversion)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) PURE;
    STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) PURE;
    STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter) PURE;
    STDMETHOD(CreateDevice)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, struct IDirect3DDevice9** ppReturnedDeviceInterface) PURE;
    /*** IDirect3D9Ex methods ***/
    STDMETHOD_(UINT, GetAdapterModeCountEx)(THIS_ UINT Adapter, CONST D3DDISPLAYMODEFILTER *pFilter) PURE;
    STDMETHOD(EnumAdapterModesEx)(THIS_ UINT Adapter, CONST D3DDISPLAYMODEFILTER *pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode) PURE;
    STDMETHOD(GetAdapterDisplayModeEx)(THIS_ UINT Adapter, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation);
    STDMETHOD(CreateDeviceEx)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode, struct IDirect3DDevice9Ex **ppReturnedDeviceInterface) PURE;
    STDMETHOD(GetAdapterLUID)(THIS_ UINT Adatper, LUID *pLUID) PURE;
};
#ce

Global Const $IDirect3D9_vTable = $IUnknown_vTable & "ptr RegisterSoftwareDevice; ptr GetAdapterCount; ptr GetAdapterIdentifier; ptr GetAdapterModeCount; " & _
        "ptr EnumAdapterModes; ptr GetAdapterDisplayMode; ptr CheckDeviceType; ptr CheckDeviceFormat; ptr CheckDeviceMultiSampleType; ptr CheckDepthStencilMatch; " & _
        "ptr CheckDeviceFormatConversion; ptr GetDeviceCaps; ptr GetAdapterMonitor; ptr CreateDevice;"
Global Const $IDirect3D9Ex_vTable = $IDirect3D9_vTable & "ptr GetAdapterModeCountEx; ptr EnumAdapterModesEx; ptr GetAdapterDisplayModeEx; ptr CreateDeviceEx; GetAdapterLUID;"
Global Const $IDirect3D9 = "ptr IDirect3D9;"
Global Const $IDirect3D9Ex = "ptr IDirect3D9Ex;"
#EndRegion

#Region IDirect3DDevice9 interface
#cs
/*****************************************************************************
 * IDirect3DDevice9 interface
 */
#define INTERFACE IDirect3DDevice9
DECLARE_INTERFACE_(IDirect3DDevice9,IUnknown)
{
    /*** IUnknown methods ***/
    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
    STDMETHOD_(ULONG,Release)(THIS) PURE;
    /*** IDirect3DDevice9 methods ***/
    STDMETHOD(TestCooperativeLevel)(THIS) PURE;
    STDMETHOD_(UINT, GetAvailableTextureMem)(THIS) PURE;
    STDMETHOD(EvictManagedResources)(THIS) PURE;
    STDMETHOD(GetDirect3D)(THIS_ IDirect3D9** ppD3D9) PURE;
    STDMETHOD(GetDeviceCaps)(THIS_ D3DCAPS9* pCaps) PURE;
    STDMETHOD(GetDisplayMode)(THIS_ UINT iSwapChain, D3DDISPLAYMODE* pMode) PURE;
    STDMETHOD(GetCreationParameters)(THIS_ D3DDEVICE_CREATION_PARAMETERS *pParameters) PURE;
    STDMETHOD(SetCursorProperties)(THIS_ UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) PURE;
    STDMETHOD_(void, SetCursorPosition)(THIS_ int X,int Y, DWORD Flags) PURE;
    STDMETHOD_(BOOL, ShowCursor)(THIS_ BOOL bShow) PURE;
    STDMETHOD(CreateAdditionalSwapChain)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) PURE;
    STDMETHOD(GetSwapChain)(THIS_ UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) PURE;
    STDMETHOD_(UINT, GetNumberOfSwapChains)(THIS) PURE;
    STDMETHOD(Reset)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters) PURE;
    STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion) PURE;
    STDMETHOD(GetBackBuffer)(THIS_ UINT iSwapChain, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) PURE;
    STDMETHOD(GetRasterStatus)(THIS_ UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) PURE;
    STDMETHOD(SetDialogBoxMode)(THIS_ BOOL bEnableDialogs) PURE;
    STDMETHOD_(void, SetGammaRamp)(THIS_ UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp) PURE;
    STDMETHOD_(void, GetGammaRamp)(THIS_ UINT iSwapChain, D3DGAMMARAMP* pRamp) PURE;
    STDMETHOD(CreateTexture)(THIS_ UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateVolumeTexture)(THIS_ UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateCubeTexture)(THIS_ UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateVertexBuffer)(THIS_ UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateIndexBuffer)(THIS_ UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateRenderTarget)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateDepthStencilSurface)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) PURE;
    STDMETHOD(UpdateSurface)(THIS_ IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) PURE;
    STDMETHOD(UpdateTexture)(THIS_ IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) PURE;
    STDMETHOD(GetRenderTargetData)(THIS_ IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) PURE;
    STDMETHOD(GetFrontBufferData)(THIS_ UINT iSwapChain, IDirect3DSurface9* pDestSurface) PURE;
    STDMETHOD(StretchRect)(THIS_ IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) PURE;
    STDMETHOD(ColorFill)(THIS_ IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) PURE;
    STDMETHOD(CreateOffscreenPlainSurface)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) PURE;
    STDMETHOD(SetRenderTarget)(THIS_ DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) PURE;
    STDMETHOD(GetRenderTarget)(THIS_ DWORD RenderTargetIndex, IDirect3DSurface9** ppRenderTarget) PURE;
    STDMETHOD(SetDepthStencilSurface)(THIS_ IDirect3DSurface9* pNewZStencil) PURE;
    STDMETHOD(GetDepthStencilSurface)(THIS_ IDirect3DSurface9** ppZStencilSurface) PURE;
    STDMETHOD(BeginScene)(THIS) PURE;
    STDMETHOD(EndScene)(THIS) PURE;
    STDMETHOD(Clear)(THIS_ DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) PURE;
    STDMETHOD(SetTransform)(THIS_ D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) PURE;
    STDMETHOD(GetTransform)(THIS_ D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) PURE;
    STDMETHOD(MultiplyTransform)(THIS_ D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*) PURE;
    STDMETHOD(SetViewport)(THIS_ CONST D3DVIEWPORT9* pViewport) PURE;
    STDMETHOD(GetViewport)(THIS_ D3DVIEWPORT9* pViewport) PURE;
    STDMETHOD(SetMaterial)(THIS_ CONST D3DMATERIAL9* pMaterial) PURE;
    STDMETHOD(GetMaterial)(THIS_ D3DMATERIAL9* pMaterial) PURE;
    STDMETHOD(SetLight)(THIS_ DWORD Index, CONST D3DLIGHT9*) PURE;
    STDMETHOD(GetLight)(THIS_ DWORD Index, D3DLIGHT9*) PURE;
    STDMETHOD(LightEnable)(THIS_ DWORD Index, BOOL Enable) PURE;
    STDMETHOD(GetLightEnable)(THIS_ DWORD Index, BOOL* pEnable) PURE;
    STDMETHOD(SetClipPlane)(THIS_ DWORD Index, CONST float* pPlane) PURE;
    STDMETHOD(GetClipPlane)(THIS_ DWORD Index, float* pPlane) PURE;
    STDMETHOD(SetRenderState)(THIS_ D3DRENDERSTATETYPE State, DWORD Value) PURE;
    STDMETHOD(GetRenderState)(THIS_ D3DRENDERSTATETYPE State, DWORD* pValue) PURE;
    STDMETHOD(CreateStateBlock)(THIS_ D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppSB) PURE;
    STDMETHOD(BeginStateBlock)(THIS) PURE;
    STDMETHOD(EndStateBlock)(THIS_ IDirect3DStateBlock9** ppSB) PURE;
    STDMETHOD(SetClipStatus)(THIS_ CONST D3DCLIPSTATUS9* pClipStatus) PURE;
    STDMETHOD(GetClipStatus)(THIS_ D3DCLIPSTATUS9* pClipStatus) PURE;
    STDMETHOD(GetTexture)(THIS_ DWORD Stage, IDirect3DBaseTexture9** ppTexture) PURE;
    STDMETHOD(SetTexture)(THIS_ DWORD Stage, IDirect3DBaseTexture9* pTexture) PURE;
    STDMETHOD(GetTextureStageState)(THIS_ DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) PURE;
    STDMETHOD(SetTextureStageState)(THIS_ DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) PURE;
    STDMETHOD(GetSamplerState)(THIS_ DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) PURE;
    STDMETHOD(SetSamplerState)(THIS_ DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) PURE;
    STDMETHOD(ValidateDevice)(THIS_ DWORD* pNumPasses) PURE;
    STDMETHOD(SetPaletteEntries)(THIS_ UINT PaletteNumber, CONST PALETTEENTRY* pEntries) PURE;
    STDMETHOD(GetPaletteEntries)(THIS_ UINT PaletteNumber,PALETTEENTRY* pEntries) PURE;
    STDMETHOD(SetCurrentTexturePalette)(THIS_ UINT PaletteNumber) PURE;
    STDMETHOD(GetCurrentTexturePalette)(THIS_ UINT *PaletteNumber) PURE;
    STDMETHOD(SetScissorRect)(THIS_ CONST RECT* pRect) PURE;
    STDMETHOD(GetScissorRect)(THIS_ RECT* pRect) PURE;
    STDMETHOD(SetSoftwareVertexProcessing)(THIS_ BOOL bSoftware) PURE;
    STDMETHOD_(BOOL, GetSoftwareVertexProcessing)(THIS) PURE;
    STDMETHOD(SetNPatchMode)(THIS_ float nSegments) PURE;
    STDMETHOD_(float, GetNPatchMode)(THIS) PURE;
    STDMETHOD(DrawPrimitive)(THIS_ D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) PURE;
    STDMETHOD(DrawIndexedPrimitive)(THIS_ D3DPRIMITIVETYPE, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) PURE;
    STDMETHOD(DrawPrimitiveUP)(THIS_ D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) PURE;
    STDMETHOD(DrawIndexedPrimitiveUP)(THIS_ D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT PrimitiveCount, CONST void* pIndexData, D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) PURE;
    STDMETHOD(ProcessVertices)(THIS_ UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) PURE;
    STDMETHOD(CreateVertexDeclaration)(THIS_ CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) PURE;
    STDMETHOD(SetVertexDeclaration)(THIS_ IDirect3DVertexDeclaration9* pDecl) PURE;
    STDMETHOD(GetVertexDeclaration)(THIS_ IDirect3DVertexDeclaration9** ppDecl) PURE;
    STDMETHOD(SetFVF)(THIS_ DWORD FVF) PURE;
    STDMETHOD(GetFVF)(THIS_ DWORD* pFVF) PURE;
    STDMETHOD(CreateVertexShader)(THIS_ CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) PURE;
    STDMETHOD(SetVertexShader)(THIS_ IDirect3DVertexShader9* pShader) PURE;
    STDMETHOD(GetVertexShader)(THIS_ IDirect3DVertexShader9** ppShader) PURE;
    STDMETHOD(SetVertexShaderConstantF)(THIS_ UINT StartRegister, CONST float* pConstantData, UINT Vector4fCount) PURE;
    STDMETHOD(GetVertexShaderConstantF)(THIS_ UINT StartRegister, float* pConstantData, UINT Vector4fCount) PURE;
    STDMETHOD(SetVertexShaderConstantI)(THIS_ UINT StartRegister, CONST int* pConstantData, UINT Vector4iCount) PURE;
    STDMETHOD(GetVertexShaderConstantI)(THIS_ UINT StartRegister, int* pConstantData, UINT Vector4iCount) PURE;
    STDMETHOD(SetVertexShaderConstantB)(THIS_ UINT StartRegister, CONST BOOL* pConstantData, UINT  BoolCount) PURE;
    STDMETHOD(GetVertexShaderConstantB)(THIS_ UINT StartRegister, BOOL* pConstantData, UINT BoolCount) PURE;
    STDMETHOD(SetStreamSource)(THIS_ UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) PURE;
    STDMETHOD(GetStreamSource)(THIS_ UINT StreamNumber, IDirect3DVertexBuffer9** ppStreamData, UINT* OffsetInBytes, UINT* pStride) PURE;
    STDMETHOD(SetStreamSourceFreq)(THIS_ UINT StreamNumber, UINT Divider) PURE;
    STDMETHOD(GetStreamSourceFreq)(THIS_ UINT StreamNumber, UINT* Divider) PURE;
    STDMETHOD(SetIndices)(THIS_ IDirect3DIndexBuffer9* pIndexData) PURE;
    STDMETHOD(GetIndices)(THIS_ IDirect3DIndexBuffer9** ppIndexData) PURE;
    STDMETHOD(CreatePixelShader)(THIS_ CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) PURE;
    STDMETHOD(SetPixelShader)(THIS_ IDirect3DPixelShader9* pShader) PURE;
    STDMETHOD(GetPixelShader)(THIS_ IDirect3DPixelShader9** ppShader) PURE;
    STDMETHOD(SetPixelShaderConstantF)(THIS_ UINT StartRegister, CONST float* pConstantData, UINT Vector4fCount) PURE;
    STDMETHOD(GetPixelShaderConstantF)(THIS_ UINT StartRegister, float* pConstantData, UINT Vector4fCount) PURE;
    STDMETHOD(SetPixelShaderConstantI)(THIS_ UINT StartRegister, CONST int* pConstantData, UINT Vector4iCount) PURE;
    STDMETHOD(GetPixelShaderConstantI)(THIS_ UINT StartRegister, int* pConstantData, UINT Vector4iCount) PURE;
    STDMETHOD(SetPixelShaderConstantB)(THIS_ UINT StartRegister, CONST BOOL* pConstantData, UINT  BoolCount) PURE;
    STDMETHOD(GetPixelShaderConstantB)(THIS_ UINT StartRegister, BOOL* pConstantData, UINT BoolCount) PURE;
    STDMETHOD(DrawRectPatch)(THIS_ UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) PURE;
    STDMETHOD(DrawTriPatch)(THIS_ UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) PURE;
    STDMETHOD(DeletePatch)(THIS_ UINT Handle) PURE;
    STDMETHOD(CreateQuery)(THIS_ D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) PURE;
#ce

Global Const $IDirect3DDevice9_vTable = $IUnknown_vTable & _ 
        "ptr TestCooperativeLevel;" & _
        "ptr GetAvailableTextureMem;" & _
        "ptr EvictManagedResources;" & _
        "ptr GetDirect3D;" & _
        "ptr GetDeviceCaps;" & _
        "ptr GetDisplayMode;" & _
        "ptr GetCreationParameters;" & _
        "ptr SetCursorProperties;" & _
        "ptr SetCursorPosition;" & _
        "ptr ShowCursor;" & _
        "ptr CreateAdditionalSwapChain;" & _
        "ptr GetSwapChain;" & _
        "ptr GetNumberOfSwapChains;" & _
        "ptr Reset;" & _
        "ptr Present;" & _
        "ptr GetBackBuffer;" & _
        "ptr GetRasterStatus;" & _
        "ptr SetDialogBoxMode;" & _
        "ptr SetGammaRamp;" & _
        "ptr GetGammaRamp;" & _
        "ptr CreateTexture;" & _
        "ptr CreateVolumeTexture;" & _
        "ptr CreateCubeTexture;" & _
        "ptr CreateVertexBuffer;" & _
        "ptr CreateIndexBuffer;" & _
        "ptr CreateRenderTarget;" & _
        "ptr CreateDepthStencilSurface;" & _
        "ptr UpdateSurface;" & _
        "ptr UpdateTexture;" & _
        "ptr GetRenderTargetData;" & _
        "ptr GetFrontBufferData;" & _
        "ptr StretchRect;" & _
        "ptr ColorFill;" & _
        "ptr CreateOffscreenPlainSurface;" & _
        "ptr SetRenderTarget;" & _
        "ptr GetRenderTarget;" & _
        "ptr SetDepthStencilSurface;" & _
        "ptr GetDepthStencilSurface;" & _
        "ptr BeginScene;" & _
        "ptr EndScene;" & _
        "ptr Clear;" & _
        "ptr SetTransform;" & _
        "ptr GetTransform;" & _
        "ptr MultiplyTransform;" & _
        "ptr SetViewport;" & _
        "ptr GetViewport;" & _
        "ptr SetMaterial;" & _
        "ptr GetMaterial;" & _
        "ptr SetLight;" & _
        "ptr GetLight;" & _
        "ptr LightEnable;" & _
        "ptr GetLightEnable;" & _
        "ptr SetClipPlane;" & _
        "ptr GetClipPlane;" & _
        "ptr SetRenderState;" & _
        "ptr GetRenderState;" & _
        "ptr CreateStateBlock;" & _
        "ptr BeginStateBlock;" & _
        "ptr EndStateBlock;" & _
        "ptr SetClipStatus;" & _
        "ptr GetClipStatus;" & _
        "ptr GetTexture;" & _
        "ptr SetTexture;" & _
        "ptr GetTextureStageState;" & _
        "ptr SetTextureStageState;" & _
        "ptr GetSamplerState;" & _
        "ptr SetSamplerState;" & _
        "ptr ValidateDevice;" & _
        "ptr SetPaletteEntries;" & _
        "ptr GetPaletteEntries;" & _
        "ptr SetCurrentTexturePalette;" & _
        "ptr GetCurrentTexturePalette;" & _
        "ptr SetScissorRect;" & _
        "ptr GetScissorRect;" & _
        "ptr SetSoftwareVertexProcessing;" & _
        "ptr GetSoftwareVertexProcessing;" & _
        "ptr SetNPatchMode;" & _
        "ptr GetNPatchMode;" & _
        "ptr DrawPrimitive;" & _
        "ptr DrawIndexedPrimitive;" & _
        "ptr DrawPrimitiveUP;" & _
        "ptr DrawIndexedPrimitiveUP;" & _
        "ptr ProcessVertices;" & _
        "ptr CreateVertexDeclaration;" & _
        "ptr SetVertexDeclaration;" & _
        "ptr GetVertexDeclaration;" & _
        "ptr SetFVF;" & _
        "ptr GetFVF;" & _
        "ptr CreateVertexShader;" & _
        "ptr SetVertexShader;" & _
        "ptr GetVertexShader;" & _
        "ptr SetVertexShaderConstantF;" & _
        "ptr GetVertexShaderConstantF;" & _
        "ptr SetVertexShaderConstantI;" & _
        "ptr GetVertexShaderConstantI;" & _
        "ptr SetVertexShaderConstantB;" & _
        "ptr GetVertexShaderConstantB;" & _
        "ptr SetStreamSource;" & _
        "ptr GetStreamSource;" & _
        "ptr SetStreamSourceFreq;" & _
        "ptr GetStreamSourceFreq;" & _
        "ptr SetIndices;" & _
        "ptr GetIndices;" & _
        "ptr CreatePixelShader;" & _
        "ptr SetPixelShader;" & _
        "ptr GetPixelShader;" & _
        "ptr SetPixelShaderConstantF;" & _
        "ptr GetPixelShaderConstantF;" & _
        "ptr SetPixelShaderConstantI;" & _
        "ptr GetPixelShaderConstantI;" & _
        "ptr SetPixelShaderConstantB;" & _
        "ptr GetPixelShaderConstantB;" & _
        "ptr DrawRectPatch;" & _
        "ptr DrawTriPatch;" & _
        "ptr DeletePatch;" & _
        "ptr CreateQuery;"
Global Const $IDirect3DDevice9 = "ptr IDirect3DDevice9;"
#EndRegion




;Prog@ndy
Func _CreateIDirect3D9($SDKVersion=$D3D_SDK_VERSION)
    Local $D3D9_Pointer = DllCall("d3d9.dll","ptr","Direct3DCreate9","uint",$SDKVersion)
    Select
        Case @error 
            Return SetError(1,0,0)
        Case $D3D9_Pointer[0] = 0
            Return SetError(2,0,0)
    EndSelect
    Local $RetArr[3]
    $RetArr[0] = $D3D9_Pointer[0]
    $RetArr[1] = DllStructCreate($IDirect3D9,$RetArr[0])
    $RetArr[2] = DllStructCreate($IDirect3D9_vTable,DllStructGetData($RetArr[1],1))
    Return $RetArr
EndFunc
;Prog@ndy
Func _IDirect3D9_Release(ByRef $D3D9Arr)
    If UBound($D3D9Arr) <> 3 Then Return SetError(1,0,-1)
    Local $Func_Release = DllStructGetData($D3D9Arr[2],"Release")
    Local $ret = MemoryFuncCall("lresult",$Func_Release,"ptr",$D3D9Arr[0])
    Return $ret[0]
EndFunc
;Prog@ndy
Func _IDirect3D9_CreateDevice(ByRef $D3D9Arr,$Adapter,$DeviceType,$hFocusWindow,$BehaviorFlags,$pPresentationParameters)
    If UBound($D3D9Arr) <> 3 Then Return SetError(1,0,-1)
    Local $Func_CreateDevice = DllStructGetData($D3D9Arr[2],"CreateDevice")
    Local $ret = MemoryFuncCall("lresult",$Func_CreateDevice,"ptr",$D3D9Arr[0],"uint",$Adapter,"dword",$DeviceType,"hwnd",$hFocusWindow,"dword",$BehaviorFlags, "ptr", $pPresentationParameters,"ptr*",0)
    Return SetError($ret[0],0,$ret[7])
EndFunc
;Prog@ndy
Func _IDirect3DDevice9_FromPointer($D3D9Device_ptr)
    if $D3D9Device_ptr = 0 Then Return SetError(1,0,0)
    Local $RetArr[3]
    $RetArr[0] = $D3D9Device_ptr
    $RetArr[1] = DllStructCreate($IDirect3DDevice9,$RetArr[0])
    $RetArr[2] = DllStructCreate($IDirect3DDevice9_vTable,DllStructGetData($RetArr[1],1))
    Return $RetArr
EndFunc
;Prog@ndy
Func _IDirect3DDevice9_Release(ByRef $D3D9Arr)
    If UBound($D3D9Arr) <> 3 Then Return SetError(1,0,-1)
    Local $Func_Release = DllStructGetData($D3D9Arr[2],"Release")
    Local $ret = MemoryFuncCall("lresult",$Func_Release,"ptr",$D3D9Arr[0])
    Return $ret[0]
EndFunc
;Prog@ndy
Func _IDirect3DDevice9_BeginScene(ByRef $D3D9Arr)
    If UBound($D3D9Arr) <> 3 Then Return SetError(1,0,-1)
    Local $DeviceFunc_BeginScene = DllStructGetData($D3D9Arr[2],"BeginScene")
    Local $BeginScene = MemoryFuncCall("lresult",$DeviceFunc_BeginScene,"ptr",$D3D9Arr[0])
    Return $BeginScene[0]
EndFunc
;Prog@ndy
Func _IDirect3DDevice9_Present(ByRef $D3D9Arr,$pSourceRect,$pDestRect,$hDestWindowOverride,$pDirtyRegion)
    If UBound($D3D9Arr) <> 3 Then Return SetError(1,0,-1)
    Local $DeviceFunc_Present = DllStructGetData($D3D9Arr[2],"Present")
    Local $Present = MemoryFuncCall("lresult",$DeviceFunc_Present,"ptr",$D3D9Arr[0],"ptr",$pSourceRect,"ptr",$pDestRect,"hwnd",$hDestWindowOverride,"ptr",$pDirtyRegion)
    Return $Present[0]
EndFunc
;Prog@ndy
Func _IDirect3DDevice9_EndScene(ByRef $D3D9Arr)
    If UBound($D3D9Arr) <> 3 Then Return SetError(1,0,-1)
    Local $DeviceFunc_EndScene = DllStructGetData($D3D9Arr[2],"EndScene")
    Local $EndScene = MemoryFuncCall("lresult",$DeviceFunc_EndScene,"ptr",$D3D9Arr[0])
    Return $EndScene[0]
EndFunc
;Prog@ndy
Func _IDirect3DDevice9_Clear(ByRef $D3D9Arr,$Count,$pRects,$Flags,$Color,$Z,$Stencil)
    If UBound($D3D9Arr) <> 3 Then Return SetError(1,0,-1)
    Local $DeviceFunc_Clear = DllStructGetData($D3D9Arr[2],"Clear")
    Local $Clear = MemoryFuncCall("lresult",$DeviceFunc_Clear,"ptr",$D3D9Arr[0],"dword",$Count,"ptr",$pRects,"DWORD",$Flags,"dword",$Color,"float",$Z,"dword",$Stencil)
    Return $Clear[0]
EndFunc

Global $FocusWindow = GUICreate("test",400,400)
    GUISetState(@SW_SHOW)

Global $structD3DPRESENT_PARAMETERS = DllStructCreate($D3DPRESENT_PARAMETERS)
    DllStructSetData($structD3DPRESENT_PARAMETERS,"SwapEffect",3)
    DllStructSetData($structD3DPRESENT_PARAMETERS,"BackBufferWidth",400)
    DllStructSetData($structD3DPRESENT_PARAMETERS,"BackBufferWidth",400)
    DllStructSetData($structD3DPRESENT_PARAMETERS,"hDeviceWindow",$FocusWindow)
    DllStructSetData($structD3DPRESENT_PARAMETERS,"Windowed",1)
    Global $pD3DPRESENT_PARAMETERS = DllStructGetPtr($structD3DPRESENT_PARAMETERS)

$MY_IDirect3D9 = _CreateIDirect3D9()

; Get Device Interface
$BehaviorFlags = $D3DCREATE_SOFTWARE_VERTEXPROCESSING
;~ $BehaviorFlags = $D3DCREATE_MIXED_VERTEXPROCESSING
;~ $BehaviorFlags = $D3DCREATE_HARDWARE_VERTEXPROCESSING
$ret = _IDirect3D9_CreateDevice($MY_IDirect3D9,$D3DADPATER_DEFAULT,$D3DDEVTYPE_HAL,$FocusWindow,$BehaviorFlags, $pD3DPRESENT_PARAMETERS)
If @error Then Exit MsgBox(0, "",@error=$D3DERR_INVALIDCALL)
$MY_D3D9Device = _IDirect3DDevice9_FromPointer($ret)

; Create Rect struct for drawing
Global $structD3DRECT = DllStructCreate($D3DRECT)

; start scene drawing
_Timer_SetTimer($FocusWindow,250,"_Timer_RedrawScene")
While GUIGetMsg()<>-3
WEnd
; stop it
_Timer_KillAllTimers($FocusWindow)

; Release Device
;~ $Func_ReleaseDevice = DllStructGetData($D3D9Device_FuncPtrs,3)
;~ $ret = MemoryFuncCall("dword",$Func_ReleaseDevice,"ptr",$D3D9Device_ptr)
$ret = _IDirect3DDevice9_Release($MY_D3D9Device)
MsgBox(0, 'Release Device', $ret=0)

; Release D3D9
;~ $Func_Release = DllStructGetData($D3D9_FuncPointers,"Release")
;~ $ret = MemoryFuncCall("dword",$Func_Release,"ptr",$D3D9_Pointer)
$ret = _IDirect3D9_Release($MY_IDirect3D9)
MsgBox(0, 'Release D3D9', $ret=0)

; Draw Scenes
Func _Timer_RedrawScene($hWnd, $Msg, $iIDTimer, $dwTime)
    ; Begin a new scene
    Local $BeginScene = _IDirect3DDevice9_BeginScene($MY_D3D9Device)
    ; clear backgrounf to blue
    Local $Clear = _IDirect3DDevice9_Clear($MY_D3D9Device,0,0,1,0x000000FF,0,0)
    
    ; draw a red rect
        DllStructSetData($structD3DRECT,"x1",Random(10,100,1))
        DllStructSetData($structD3DRECT,"y1",Random(10,200,1))
        DllStructSetData($structD3DRECT,"x2",DllStructgetData($structD3DRECT,"x1")+Random(40,200,1))
        DllStructSetData($structD3DRECT,"y2",DllStructgetData($structD3DRECT,"y1")+Random(40,200,1))
    Local $Clear2 = _IDirect3DDevice9_Clear($MY_D3D9Device,1,DllStructGetPtr($structD3DRECT),1,0x00FF0000,0,0)
    
    ;end the scene
    Local $EndScene = _IDirect3DDevice9_EndScene($MY_D3D9Device)
    ; draw it
    Local $Present = _IDirect3DDevice9_Present($MY_D3D9Device,0,0,0,0)
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Continued a bit, because I wanted to check a window with D3D output :( ( made examples for UDF creation, too)

Wow, awesome. I was just about to ask about how to get A CreateDevice function working, but now I have a whole working set of functions :mellow:


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

It is quite same as DLLCall, you just have to get the Function Pointer from vTable :mellow:

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

It is quite same as DLLCall, you just have to get the Function Pointer from vTable :mellow:

Yeah, I get used to it. The confusing part is that the object have three different pointers (well pointers and structs) in an array.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

If you want, you can leave out the first struct :mellow: It's not needed anymore, when you got the vTable Pointer out of it.

Structure of Object:

POINTER to Obj

...|-ptr lpVTable -> Pointer to vTable

...|-possibly more variables, we mustn't have to use them.

...vTable: Array of function pointers

END Obj


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0