Ok I am trying to convert my C DirectX code into C++ so I can teach myself object oriented programming. When I compile my source code I get:
<pre lang="msil">Deleting intermediate files and output files for project 'WinAPI - Win32 Debug'.
--------------------Configuration: WinAPI - Win32 Debug--------------------
Compiling resources...
Compiling...
Error.cpp
c:\practice\final\src\includes\\main.h(20) : error C2146: syntax error : missing ';' before identifier 'DXApp'
c:\practice\final\src\includes\\main.h(20) : fatal error C1004: unexpected end of file found
Main.cpp
c:\practice\final\src\includes\\main.h(20) : error C2146: syntax error : missing ';' before identifier 'DXApp'
c:\practice\final\src\includes\\main.h(20) : fatal error C1004: unexpected end of file found
WinApp.cpp
c:\practice\final\src\includes\\main.h(20) : error C2146: syntax error : missing ';' before identifier 'DXApp'
c:\practice\final\src\includes\\main.h(20) : fatal error C1004: unexpected end of file found
WinProc.cpp
c:\practice\final\src\includes\\main.h(20) : error C2146: syntax error : missing ';' before identifier 'DXApp'
c:\practice\final\src\includes\\main.h(20) : fatal error C1004: unexpected end of file found
DirectX.cpp
c:\practice\final\src\includes\\main.h(20) : error C2146: syntax error : missing ';' before identifier 'DXApp'
c:\practice\final\src\includes\\main.h(20) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
WinAPI.exe - 10 error(s), 0 warning(s)
Which makes me think some multiple inclusion type error. Any help would be greatly appreciated.
main.h
#ifndef main_h
#define main_h
#include <windows.h>
#include <d3d9.h>
#include "Includes//WinApp.h"
#include "Includes//DirectX.h"
#pragma comment(lib, "d3d9.lib")
#define TITLE "DX Tutorial"
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
extern WinApp DXApp;
extern DirectX DX3D;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
bool Error(char *Message);
#endif
WinApp.h
#ifndef _WINAPP_H_
#define _WINAPP_H_
#include "Includes//Main.h"
class WinApp
{
public:
WinApp(void);
~WinApp(void);
bool InitWindow(void);
void KillWindow(void);
inline HWND GetWindowHandle(void){ return Wnd; }
private:
HWND Wnd;
bool RegClass(void);
bool CreateWnd(void);
};
#endif
DirectX.h
#ifndef _DIRECTX_H_
#define _DIRECTX_H_
#include "Includes//Main.h"
class DirectX{
public:
bool Setup();
bool Render();
DirectX(void);
~DirectX(void);
private:
LPDIRECT3D9 D3D_Object;
LPDIRECT3DDEVICE9 D3D_Device;
LPDIRECT3DVERTEXBUFFER9 VertexBuffer;
LPDIRECT3DINDEXBUFFER9 IndexBuffer;
bool Initialize_D3D();
bool SetupMatrices();
}
#endif
main.cpp
#include "Includes//Main.h"
WinApp DXApp;
DirectX DX3D;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
if(!DX3D.Setup()){
Error( "DirectX failed to initialize!\n
Make sure you have DirectX 9.0\n
Available from www.microsoft.com");
delete DX3D;
return 0;
}
if(DXApp.InitWindow() == FALSE){
return 0;
}
ShowWindow(DXApp.GetWindowHandle(), nCmdShow);
MSG Msg;
ZeroMemory(&Msg, sizeof(Msg));
while(TRUE){
while(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
if(Msg.message == WM_QUIT)
break;
DX3D.Render();
}
DX3D.~DirectX();
return 0;
}
DirectX.cpp
#include "Includes//main.h"
#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)
struct CUSTOM_VERTEX { float x, y, z; DWORD Color; };
DirectX::DirectX(){
}
DirectX::~DirectX(){
D3D_Device->Release();
D3D_Object->Release();
}
bool DirectX::Initialize_D3D(){
D3D_Object = Direct3DCreate9(D3D_SDK_VERSION);
if(!D3D_Object){
return false;
}
D3DPRESENT_PARAMETERS D3Dpp;
ZeroMemory(&D3Dpp, sizeof(D3Dpp));
D3Dpp.Windowed = TRUE;
D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3Dpp.hDeviceWindow = DXApp.GetWindowHandle();
D3D_Object->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
DXApp.GetWindowHandle(),
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&D3Dpp,
&D3D_Device);
}
bool DirectX::SetupMatrices(){
}
bool DirectX::Setup(){
return DX3D.Initialize_D3D();
}
bool DirectX::Render(){
D3D_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
D3D_Device->BeginScene();
D3D_Device->EndScene();
D3D_Device->Present(NULL, NULL, NULL, NULL);
}
WinApp.cpp
#include "Includes//Main.h"
#include "Resources//Resource.h"
WinApp::WinApp(void)
{
}
bool WinApp::RegClass(void)
{
WNDCLASSEX WindowClass;
WindowClass.cbSize = sizeof(WNDCLASSEX);
WindowClass.style = CS_HREDRAW | CS_VREDRAW;
WindowClass.lpfnWndProc = WndProc;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hInstance = GetModuleHandle(NULL);
WindowClass.hIcon = LoadIcon(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_ICON1));
WindowClass.hCursor = NULL;
WindowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WindowClass.lpszMenuName = NULL;
WindowClass.lpszClassName = "ClassName";
WindowClass.hIconSm = LoadIcon(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_ICON1));
if(!RegisterClassEx(&WindowClass)){
return FALSE;
}
return TRUE;
}
bool WinApp::CreateWnd(void){
Wnd = CreateWindowEx( WS_EX_CLIENTEDGE, "ClassName", TITLE,
WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH,
SCREEN_HEIGHT, NULL, NULL, GetModuleHandle(NULL),
NULL);
if(Wnd==NULL){
return FALSE;
}
return TRUE;
}
bool WinApp::InitWindow(void){
if(DXApp.RegClass() == FALSE){
return Error( "Class Registration Failed!");
}
if(DXApp.CreateWnd() == FALSE){
return Error("Window Creation Failed!");
}
return TRUE;
}
void WinApp::KillWindow(void){
UnregisterClass("ClassName",GetModuleHandle(NULL));
}
WinApp::~WinApp(void){
KillWindow();
}