WolfgangEngel

Hi,

I am trying to compile a DX10 program with a LCC based C99 compatible compiler. It works fine with DirectX 9, but with DirectX 10 I get an error message in the dxgi.h header in line 287 that says: "Missing Parameter type '__RPC__deref_out'"

This error repeats then a couple of times, because it is quite often in the file.

In d3d10.h I get an error message in line 865 saying: Syntax error: found 'ID3D10Device' - expecting ')' and missing parameter type __in later

in line 879 I get a "Duplicate field name 'guid' in [incomplete] struct ID3D10DeviceChildVtbl' ...

and there are others as well.

If there is a way to fix this easily in my headers, I would appreciate your advice,

- Wolfgang



Re: Direct3D 10 Compiling DX10 example with C99 compatible compiler (Pelles C)

Christian Lavallee

__RPC__deref_out and __in are sal annotations. Try including rpcsal.h and sal.h




Re: Direct3D 10 Compiling DX10 example with C99 compatible compiler (Pelles C)

WolfgangEngel

Thanks! I am curious what is a sal annotation



Re: Direct3D 10 Compiling DX10 example with C99 compatible compiler (Pelles C)

Christian Lavallee

SAL stands for Standard Annotation Language and it's basically annotations to help you find bugs. But I think these 2 links should describe it way better than I can :

http://blogs.msdn.com/michael_howard/archive/2006/05/19/602077.aspx

http://msdn2.microsoft.com/en-us/library/ms235402(vs.80).aspx






Re: Direct3D 10 Compiling DX10 example with C99 compatible compiler (Pelles C)

WolfgangEngel

Thanks again!

It seems on my way to compile a DX10 program with Pelles C there is only one problem left. If anyone could give me a helping hand with getting the GUID under C.

g_pSwapChain->lpVtbl->GetBuffer( g_pSwapChain, 0, __uiidof(ID3D10Texture2D), (LPVOID*)&(pBackBuffer) ) ;

This is what I have. Initially I thought that IID_ID3D10Texture2D would help here, but it doesn't. The compiler gives me the following error message.

C:\ExampleSpace\Intro Programming\Intro VX1\Window.c(102): warning #2027: Missing prototype for '__uiidof'.
C:\ExampleSpace\Intro Programming\Intro VX1\Window.c(102): error #2066: Illegal use of type name 'ID3D10Texture2D'.
C:\ExampleSpace\Intro Programming\Intro VX1\Window.c(102): error #2140: Type error in argument 3 to a function; found 'int' expected 'const const struct _GUID *'.
*** Error code: 1 ***

I looked into d3d10.h and it seems like lots of this stuff is only available for C++. I can see that the define for __uiidof seems to be only available in C++.

Thanks in advance for your help,
- Wolfgang









Re: Direct3D 10 Compiling DX10 example with C99 compatible compiler (Pelles C)

Alexey Barkovoy

Have you tried replacing whole "__uiidof(ID3D10Texture2D)" with IID_ID3D10Texture2D



Re: Direct3D 10 Compiling DX10 example with C99 compatible compiler (Pelles C)

WolfgangEngel

Hey Alexey,
thanks a lot for helping me here. Yes I tried it. Here is the code:

g_pSwapChain->lpVtbl->GetBuffer( g_pSwapChain, 0, (REFIID ) IID_ID3D10Texture2D, (LPVOID*)&(pBackBuffer) ) ;

The error message is

C:\ExampleSpace\Intro Programming\Intro VX1\Window.c(102): error #2051: Cast from 'struct _GUID' to 'const const struct _GUID *' is illegal.
C:\ExampleSpace\Intro Programming\Intro VX1\Window.c(102): error #2140: Type error in argument 3 to a function; found 'int' expected 'const const struct _GUID *'.

C99 does not seem to allow the type cast necessary here. Changing it manually to

const struct _GUID* pTex2D = &IID_ID3D10Texture2D;
g_pSwapChain->lpVtbl->GetBuffer( g_pSwapChain, 0, (REFIID ) pTex2D, (LPVOID*)&(pBackBuffer) ) ;

leads to a linker error message that tells me

POLINK: error: Unresolved external symbol '_IID_ID3D10Texture2D'.
POLINK: fatal error: 1 unresolved external(s).

This is how far I got ... if anyone has some insight I would appreciate it.

- Wolfgang




Re: Direct3D 10 Compiling DX10 example with C99 compatible compiler (Pelles C)

Alexey Barkovoy

So, "&IID_ID3D10Texture2D" is the correct way to pass IID to function.

Now you need either to link to LIB containing appropriate GUIDs or to rebuild with ' #define INITGUID ' line added before including DirectX headers.





Re: Direct3D 10 Compiling DX10 example with C99 compatible compiler (Pelles C)

WolfgangEngel

Hey thanks so much. It is working!



Re: Direct3D 10 Compiling DX10 example with C99 compatible compiler (Pelles C)

WolfgangEngel

Here is the working version. You can see that this example shows ways on not to program windows :-). It is meant for doing intro programming with DX10. The thing I do not get currently is, why the DX9 version of the example is 0.75 kb and the DX10 version is 1.65kb ... but anyway I gave up on this for now to do more serious work. Thought someone might find it useful :-)

////////////////////////////////////////////////////////////////////////
//
// Skeleton Intro Coding
//
// by Wolfgang Engel
// Last time modified: 01/13/2007
//
///////////////////////////////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN
#define INITGUID
#include <windows.h>
#include <sal.h>
#include <rpcsal.h>

#include <d3d10.h>


// define full screen & to use the desktop window
// #define FULLSCREENUSE_DESKTOP

#if defined(FULLSCREENUSE_DESKTOP)
   // define the size of the full-screen
   #define WINWIDTH 1280
   #define WINHEIGHT 720
#else
   // define the size of the window
   #define WINWIDTH 800
   #define WINHEIGHT 600
#endif

// makes the applicaton behave well with windows
// allows to remove some system calls to reduce size
#define WELLBEHAVIOUR

// D3D 10 device variables
// Global Variables:
ID3D10Device *g_pd3dDevice = NULL;
IDXGISwapChain *g_pSwapChain = NULL;
ID3D10RenderTargetView *g_pRenderTargetView = NULL;

// main window handle
HWND      g_MainWnd;

// timer global variables
DWORD      g_StartTime;
DWORD      g_CurrentTime;

// keep track if the game loop is still running
BOOL      g_BRunning;

// this is the main windows entry point ... the assembly version is in crt0gui.asm
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
   // using the desktop window saves even more size
#if defined(FULLSCREENUSE_DESKTOP)
   HWND hWnd = GetDesktopWindow();
#else
   // the most simple window
   HWND hWnd = CreateWindowEx(WS_EX_TOPMOST,
                        "STATIC",
                        0,
                        WS_POPUP | WS_VISIBLE,
                        0, 0,
                        WINWIDTH, WINHEIGHT,
                        0, 0, 0, 0);

   // don't show the cursor
   ShowCursor(FALSE);
#endif

   DXGI_SWAP_CHAIN_DESC sd;
   //ZeroMemory( &sd, sizeof(sd) );
   sd.BufferCount = 1;
   sd.BufferDesc.Width = WINWIDTH;
   sd.BufferDesc.Height = WINHEIGHT;
   sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
   sd.BufferDesc.RefreshRate.Numerator = 75;
   sd.BufferDesc.RefreshRate.Denominator = 1;
   sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
   sd.OutputWindow = hWnd;
   sd.SampleDesc.Count = 1;
   sd.SampleDesc.Quality = 0;

   // full-screen or not
#if defined(FULLSCREENUSE_DESKTOP)
   sd.Windowed = FALSE;
#else
   sd.Windowed = TRUE;
#endif

   D3D10CreateDeviceAndSwapChain( NULL,
                           D3D10_DRIVER_TYPE_REFERENCE,
                           (HMODULE)0,
                           0,
                           D3D10_SDK_VERSION,
                           &sd,
                           &g_pSwapChain,
                           &g_pd3dDevice );

   // Create a render target view
   ID3D10Texture2D *pBackBuffer;
   g_pSwapChain->lpVtbl->GetBuffer( g_pSwapChain, 0, (REFIID ) &IID_ID3D10Texture2D, (LPVOID*)&(pBackBuffer) ) ;
   g_pd3dDevice->lpVtbl->CreateRenderTargetView( g_pd3dDevice, (struct ID3D10Resource *)pBackBuffer, NULL, &g_pRenderTargetView );
   g_pd3dDevice->lpVtbl->OMSetRenderTargets( g_pd3dDevice, 1, &g_pRenderTargetView, NULL );

   // Setup the viewport
   D3D10_VIEWPORT vp;
   vp.Width = WINWIDTH;
   vp.Height = WINHEIGHT;
   vp.MinDepth = 0;
   vp.MaxDepth = 1;
   vp.TopLeftX = 0;
   vp.TopLeftY = 0;
   g_pd3dDevice->lpVtbl->RSSetViewports( g_pd3dDevice, 1, &vp );

   // setup timer
   g_StartTime = GetTickCount();
   g_CurrentTime = 0;   

   // set the game loop to running by default
   g_BRunning = TRUE;
   MSG msg;

   while (g_BRunning)
   {
#if defined(WELLBEHAVIOUR)
      // Just remove the message
      PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE);
#endif
      // Calculate the current demo time
      g_CurrentTime = GetTickCount() - g_StartTime;

      // go out of game loop and shutdown
      if (g_CurrentTime > 15300)
         g_BRunning = FALSE;

      float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f };
      g_pd3dDevice->lpVtbl->ClearRenderTargetView(g_pd3dDevice, g_pRenderTargetView, ClearColor );

      g_pSwapChain->lpVtbl->Present( g_pSwapChain, 0, 0 );
   }

   // release all D3D device related resources
#if defined(WELLBEHAVIOUR)
       if( g_pd3dDevice ) g_pd3dDevice->lpVtbl->ClearState(g_pd3dDevice);
       if( g_pd3dDevice ) g_pd3dDevice->lpVtbl->Release(g_pd3dDevice);
       if( g_pRenderTargetView ) g_pRenderTargetView->lpVtbl->Release(g_pRenderTargetView);
       if( g_pSwapChain ) g_pSwapChain->lpVtbl->Release(g_pSwapChain);
       if (pBackBuffer)pBackBuffer->lpVtbl->Release(pBackBuffer);
#endif

  return msg.wParam;
}

Have fun,
- Wolfgang

=== Edited by WolfgangEngel @ 13 Jan 2007 11:03 PM UTC===
Fixed it. With INITGUID I get all the GUID's as data into the program. So what I have to do is specify each separately like this:

// name the GUID's here ... other with INITGUID you will have all the GUID's in the constant table
const IID IID_ID3D10Texture2D;
DEFINE_GUID(IID_ID3D10Texture2D,0x9B7E4C04,0x342C,0x4106,0xA1,0x9F,0x4F,0x27,0x04,0xF6,0x89,0xF0);

Size goes down to 867 bytes this way. Thanks again to everybody for help and support :-)