*Zaccheus* on 25/11/2008 at 11:39
You mean like this:
Code:
DECLARE_INTERFACE_(IDirect3D8, IUnknown)
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
/*** IDirect3D8 methods ***/
STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction) PURE;
STDMETHOD_(UINT, GetAdapterCount)(THIS) PURE;
STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER8* pIdentifier) PURE;
STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter) PURE;
STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter,UINT Mode,D3DDISPLAYMODE* pMode) PURE;
STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter,D3DDISPLAYMODE* pMode) PURE;
STDMETHOD(CheckDeviceType)(THIS_ UINT Adapter,D3DDEVTYPE CheckType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL Windowed) 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) PURE;
STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) PURE;
STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS8* pCaps) PURE;
STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter) PURE;
STDMETHOD(CreateDevice)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice8** ppReturnedDeviceInterface) PURE;
};
Those macros are easy to define.
Volca on 25/11/2008 at 14:40
Is this the syntax that is always used to declare an interface? I always thought the interfaces are declared using a proprietary language extension, like this:
Code:
interface ISomething : IUnknown {
virtual void someMethod(int param);
}
This is why I was refering to the need of the rewrite of headers.
Edit: I see now - this is the syntax used in the IDL files, not the header files. That explains the confusion :)
*Zaccheus* on 25/11/2008 at 21:32
Well the above macros, when expanded by the C++ pre-processor, turn this:
Code:
DECLARE_INTERFACE_(IDirect3D8, IUnknown)
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
/*** IDirect3D8 methods ***/
STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction) PURE;
STDMETHOD_(UINT, GetAdapterCount)(THIS) PURE;
STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER8* pIdentifier) PURE;
STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter) PURE;
STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter,UINT Mode,D3DDISPLAYMODE* pMode) PURE;
STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter,D3DDISPLAYMODE* pMode) PURE;
STDMETHOD(CheckDeviceType)(THIS_ UINT Adapter,D3DDEVTYPE CheckType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL Windowed) 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) PURE;
STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) PURE;
STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS8* pCaps) PURE;
STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter) PURE;
STDMETHOD(CreateDevice)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice8** ppReturnedDeviceInterface) PURE;
};
into this:
Code:
struct IDirect3D8 : IUnknown
{
virtual HRESULT __stdcall QueryInterface( const IID & riid, void** ppvObj) = 0;
virtual ULONG __stdcall AddRef() = 0;
virtual ULONG __stdcall Release() = 0;
virtual HRESULT __stdcall RegisterSoftwareDevice( void* pInitializeFunction) = 0;
virtual UINT __stdcall GetAdapterCount() = 0;
virtual HRESULT __stdcall GetAdapterIdentifier( UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER8* pIdentifier) = 0;
virtual UINT __stdcall GetAdapterModeCount( UINT Adapter) = 0;
virtual HRESULT __stdcall EnumAdapterModes( UINT Adapter,UINT Mode,D3DDISPLAYMODE* pMode) = 0;
virtual HRESULT __stdcall GetAdapterDisplayMode( UINT Adapter,D3DDISPLAYMODE* pMode) = 0;
virtual HRESULT __stdcall CheckDeviceType( UINT Adapter,D3DDEVTYPE CheckType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL Windowed) = 0;
virtual HRESULT __stdcall CheckDeviceFormat( UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat) = 0;
virtual HRESULT __stdcall CheckDeviceMultiSampleType( UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType) = 0;
virtual HRESULT __stdcall CheckDepthStencilMatch( UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) = 0;
virtual HRESULT __stdcall GetDeviceCaps( UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS8* pCaps) = 0;
virtual HMONITOR __stdcall GetAdapterMonitor( UINT Adapter) = 0;
virtual HRESULT __stdcall CreateDevice( UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice8** ppReturnedDeviceInterface) = 0;
};
Volca on 26/11/2008 at 08:15
We still don't understand each other, it seems :)
My concern, rather theoretical, was about the original source code headers:
If those would be written using the proprietary extension
Code:
interface ISomething : IUnknown {
virtual int doSomething(int amount);
}
You'd have to do a rewrite of all those to look like this:
Code:
_DECLARE_INTERFACE(ISomething, IUnknown) {
STDMETHOD_(int, doSomething)(int amount) PURE;
}
In order to be able to use the macros you submitted.
Ajare on 26/11/2008 at 09:57
Quote Posted by Volca
We still don't understand each other, it seems :)
My concern, rather theoretical, was about the original source code headers:
If those would be written using the proprietary extension
Code:
interface ISomething : IUnknown {
virtual int doSomething(int amount);
}
You'd have to do a rewrite of all those to look like this:
Code:
_DECLARE_INTERFACE(ISomething, IUnknown) {
STDMETHOD_(int, doSomething)(int amount) PURE;
}
In order to be able to use the macros you submitted.
Proprietary extensions such as MS's __interface are always best avoided. C++ doesn't have the same notion of interfaces as other languages such as Java do, so implementing them is done with abstract base classes and maybe some template trickery.
The macros used are incredibly ugly, but they do make everything more portable.
*Zaccheus* on 26/11/2008 at 11:03
The word 'interface' is just another ugly macro:
Code:
/* objbase.h in Windows Platform SDK */
#define interface struct
What the source code looks like
before pre-processing does not matter. What matters is what the code looks like
after pre-processing.
So all these examples should end up looking the same after the C++ pre-processor is done and before the actual C++ compiler engine sees the code.
The pre-processed code should always look something like this:
Code:
struct IDirect3D8 : IUnknown
{
virtual HRESULT QueryInterface(const IID & riid, void** ppvObj) = 0;
virtual ULONG AddRef() = 0;
virtual ULONG Release() = 0;
...};
With or without __stdcall depending on compiler.