Visual C++ 2008 and DX9 compatibility

41d1769879f457df80876b1bb9e7fdd4
0
vanzagar 101 Dec 28, 2007 at 04:05

Will Visual C++ 2008 Express run programs based on the DirectX 9.0B SDK?

I can’t seem to get sample files from an old book I used to use working in Visual C++ 2008:

http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?z=y&EAN=9781931841092&itm=2

Any suggestions on how to get this program compiling would be hugely appreciated…

Here’s the compiler error:

c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(236)
error C2146: syntax error : missing ‘;’ before identifier ‘PVOID64’

In the file winnt.h, here’s code from the file (errors on the part I’ve added the –>):

#ifdef DEPRECATE_DDK_FUNCTIONS
#ifdef _NTDDK_
#define DECLSPEC_DEPRECATED_DDK DECLSPEC_DEPRECATED
#ifdef DEPRECATE_SUPPORTED
#define PRAGMA_DEPRECATED_DDK 1
#endif
#else
#define DECLSPEC_DEPRECATED_DDK
#define PRAGMA_DEPRECATED_DDK 1
#endif
#else
#define DECLSPEC_DEPRECATED_DDK
#define PRAGMA_DEPRECATED_DDK 0
#endif

//
// Void
//

--> typedef void *PVOID;
typedef void * POINTER_64 PVOID64;

Here’s the source code:

/**************************************************
WinMain.cpp
Chapter 6 2-D Drawing Demo (Draw2D)

Programming Role-Playing Games with DirectX
by Jim Adams (01 Jan 2002)

Required libraries:
  D3D9.LIB and D3DX9.LIB
**************************************************/

// Include files
#include <windows.h>
#include <stdio.h>
#include "d3d9.h"
#include "d3dx9.h"

// Window handles, class and caption text
HWND          g_hWnd;
HINSTANCE     g_hInst;
static char   g_szClass[]   = "Draw2DClass";
static char   g_szCaption[] = "Draw2D Demo by Jim Adams";

// The Direct3D and Device object
IDirect3D9       *g_pD3D       = NULL;
IDirect3DDevice9 *g_pD3DDevice = NULL;

// The 2-D vertex format and descriptor
typedef struct {
  FLOAT x, y, z;     // 2-D coordinates
  FLOAT rhw;         // rhw
  FLOAT u, v;        // Texture coordinates
} sVertex;
#define VERTEXFVF (D3DFVF_XYZRHW | D3DFVF_TEX1)

// Vertex buffer
IDirect3DVertexBuffer9 *g_pVB = NULL;

// Texture
IDirect3DTexture9 *g_pTexture = NULL;

// Function prototypes
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev,          \
                   LPSTR szCmdLine, int nCmdShow);
long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg,              \
                           WPARAM wParam, LPARAM lParam);

BOOL DoInit();
BOOL DoShutdown();
BOOL DoFrame();
BOOL SetupMeshes();

int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev,          \
                   LPSTR szCmdLine, int nCmdShow)
{
  WNDCLASSEX wcex;
  MSG        Msg;

  g_hInst = hInst;

  // Create the window class here and register it
  wcex.cbSize        = sizeof(wcex);
  wcex.style         = CS_CLASSDC;
  wcex.lpfnWndProc   = WindowProc;
  wcex.cbClsExtra    = 0;
  wcex.cbWndExtra    = 0;
  wcex.hInstance     = hInst;
  wcex.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  wcex.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wcex.hbrBackground = NULL;
  wcex.lpszMenuName  = NULL;
  wcex.lpszClassName = g_szClass;
  wcex.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  if(!RegisterClassEx(&wcex))
    return FALSE;

  // Create the Main Window
  g_hWnd = CreateWindow(g_szClass, g_szCaption,
        WS_CAPTION | WS_SYSMENU,
        0, 0, 400, 400,
        NULL, NULL,
        hInst, NULL );
  if(!g_hWnd)
    return FALSE;
  ShowWindow(g_hWnd, SW_NORMAL);
  UpdateWindow(g_hWnd);

  // Run init function and return on error
  if(DoInit() == FALSE)
    return FALSE;

  // Start message pump, waiting for signal to quit
  ZeroMemory(&Msg, sizeof(MSG));
  while(Msg.message != WM_QUIT) {
    if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
    }
    if(DoFrame() == FALSE)
      break;
  }

  // Run shutdown function
  DoShutdown();
  
  UnregisterClass(g_szClass, hInst);

  return Msg.wParam;
}

long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg,              \
                           WPARAM wParam, LPARAM lParam)
{
  switch(uMsg) {
    case WM_DESTROY:
      PostQuitMessage(0);
      return 0;

  }

  return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

BOOL DoInit()
{
  D3DPRESENT_PARAMETERS d3dpp;
  D3DDISPLAYMODE        d3ddm;
  BYTE *Ptr;
  sVertex Verts[4] = {
      {  50.0f,  50.0f, 1.0f, 1.0f, 0.0f, 0.0f },
      { 350.0f,  50.0f, 1.0f, 1.0f, 20.0f, 0.0f },
      {  50.0f, 350.0f, 1.0f, 1.0f, 0.0f, 20.0f },
      { 350.0f, 350.0f, 1.0f, 1.0f, 20.0f, 20.0f }
    };

  // Do a windowed mode initialization of Direct3D
  if((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
    return FALSE;
  if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
    return FALSE;
  ZeroMemory(&d3dpp, sizeof(d3dpp));
  d3dpp.Windowed = TRUE;
  d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  d3dpp.BackBufferFormat = d3ddm.Format;
  d3dpp.EnableAutoDepthStencil = FALSE;
  if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
                                  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                  &d3dpp, &g_pD3DDevice)))
    return FALSE;

  // Create the vertex buffer and set data
  g_pD3DDevice->CreateVertexBuffer(sizeof(sVertex)*4, 0,      \
                          VERTEXFVF, D3DPOOL_DEFAULT, &g_pVB, NULL);
  g_pVB->Lock(0,0, (VOID**)&Ptr, 0);
  memcpy(Ptr, Verts, sizeof(Verts));
  g_pVB->Unlock();

  // Load the texture map
  D3DXCreateTextureFromFile(g_pD3DDevice, "Texture.bmp", &g_pTexture);

  return TRUE;
}

BOOL DoShutdown()
{
  // Release vertex buffer
  if(g_pVB != NULL)
    g_pVB->Release();

  // Release texture
  if(g_pTexture != NULL)
    g_pTexture->Release();

  // Release device and 3D objects
  if(g_pD3DDevice != NULL)
    g_pD3DDevice->Release();

  if(g_pD3D != NULL)
    g_pD3D->Release();

  return TRUE;
}

BOOL DoFrame()
{
  // Clear device backbuffer
  g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,               \
                        D3DCOLOR_RGBA(0,64,128,255), 1.0f, 0);

  // Begin scene
  if(SUCCEEDED(g_pD3DDevice->BeginScene())) {

    // Set the vertex stream, shader, and texture
    g_pD3DDevice->SetStreamSource(0, g_pVB, 0, sizeof(sVertex));
    g_pD3DDevice->SetFVF(VERTEXFVF);
    g_pD3DDevice->SetTexture(0, g_pTexture);

    // Draw the vertex buffer
    g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

    // Release texture
    g_pD3DDevice->SetTexture(0, NULL);

    // End the scene
    g_pD3DDevice->EndScene();
  }

  // Display the scene
  g_pD3DDevice->Present(NULL, NULL, NULL, NULL);

  return TRUE;
}

5 Replies

Please log in or register to post a reply.

41d1769879f457df80876b1bb9e7fdd4
0
vanzagar 101 Dec 28, 2007 at 04:10

This program used to run fine in Visual C++ 6.0 (what I used to use), I’m wondering if I should go back to it or even Visual C++ 2005. Do you think the above program would run in Visual C++ 2005?

I can’t seem to find any books on Visual C++ 2008 except this one:

http://www.amazon.com/Ivor-Hortons-Beginning-Visual-2008/dp/0470225904/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198813624&sr=8-1

If I went back to using Visual C++ 6.0, what limitations would I run into please? One thing I read was that Visual C++ 2008 now supports dual cores so I guess that would be one, but for my small applications that would be minimal…

Really appreciate any advice…

Thanks,

Vanz

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 28, 2007 at 07:02

Visual C++ 6 is actually a quite bad compiler - it wasn’t very standard compliant, and there were a lot of things related to advanced C++ features that it just couldn’t do. As for the differences between 2003, 2005, and 2008, they are mostly things that I personally don’t care that much about (for the time being), so I don’t know off the top of my head what they are - but I’m sure someone else on the forum can fill you in.

The error you’re getting is usually caused (in my experience) by including header files in the wrong order. If you change it to put stdio.h before windows.h, does that change anything?

Also, just to let you know, you can use the tag for code samples rather than using [quote]. [code] tag for code samples rather than using

.

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Dec 28, 2007 at 16:17

@vanzagar

c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(236) : error C2146: syntax error : missing ‘;’ before identifier ‘PVOID64’

winnt.h(222): Error C2146 …

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Dec 28, 2007 at 16:34

And Nick demonstrates with his post how easy it is to find information by simply copy-pasting the error message into google :)

41d1769879f457df80876b1bb9e7fdd4
0
vanzagar 101 Dec 28, 2007 at 19:42

@.oisyn

And Nick demonstrates with his post how easy it is to find information by simply copy-pasting the error message into google :)

Doh! I didn’t even think to try google for compiler errors - lesson learned…

Thanks,

V