Click here to Skip to main content
15,867,997 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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")
//Constants
#define TITLE				"DX Tutorial"
#define SCREEN_WIDTH		800
#define SCREEN_HEIGHT		600
//Globals
extern WinApp				DXApp;
extern DirectX				DX3D;
//Function Declarations
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:
		//  Member Variables
		HWND Wnd;
		
		//  Member Functions
		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();    // close and release the 3D device
    D3D_Object->Release();    // close and release Direct3D
}
bool DirectX::Initialize_D3D(){
	D3D_Object = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface
	if(!D3D_Object){
		return false;
	}
    D3DPRESENT_PARAMETERS D3Dpp;    // create a struct to hold various device information
    ZeroMemory(&D3Dpp, sizeof(D3Dpp));    // clear out the struct for use
    D3Dpp.Windowed  = TRUE;
	D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	D3Dpp.hDeviceWindow = DXApp.GetWindowHandle();
    // create a device class using this information and the info from the d3dpp stuct
    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(){
    // clear the window to a deep blue
    D3D_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    D3D_Device->BeginScene();    // begins the 3D scene
    // do 3D rendering on the back buffer here
    
	D3D_Device->EndScene();    // ends the 3D scene
    D3D_Device->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
}


WinApp.cpp
C#
#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();
}
Posted

You have statements of the form
C++
#include "Includes//Main.h"

I think there should only be a single '/' character in the path name.
 
Share this answer
 
Comments
drkwlf 9-Apr-11 14:04pm    
Thanks for the quick response I did switch the includes to
Collapse | Copy Code
#include "includes/main.h"but I am still getting the errors

Ok I removed the includes from directx.h and winapp.cpp since they were class declarations only but again still getting the errors. If anyone can help me with this it would be greatly appreciated.

Also I started this project converting the WINAPI C source which is the same code minus all the DX stuff... It worked perfectly so it has to do something with there being two classes

By moving the #include "Includes/DirectX.h" in the main.h to after the extern WinApp DXApp; I get the same error but for the DirectX Class instead of the WinApp class


Collapse | Copy Code
c:\practice\final\src\includes\main.h(22) : error C2146: syntax error : missing ';' before identifier 'DX3D'c:\practice\final\src\includes\main.h(22) : fatal error C1004: unexpected end of file foundInstead of:

Collapse | Copy Code
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
Richard MacCutchan 9-Apr-11 14:33pm    
You also have an #include "Main.h" in WinApp.h, which looks like a circular reference, and a semi-colon missing at the end of Directx.h. I suspect the second issue is the real culprit.
drkwlf 13-Apr-11 15:20pm    
That did it thanks sorry took me so long to get back to it... Thanks again for all the help
Richard MacCutchan 13-Apr-11 16:38pm    
No problem; all feedback is welcome. You might like to mark this as answer, or upvote from the 1 someone ungenerously bestowed.
drkwlf 17-Apr-11 2:27am    
Sorry, work was hectic upvoted it today... Thanks for the help again and if you see any parts of the code that could be better feel free to email me at adams.stevenw@gmail.com I look forward to the feedback
The only feesible solution I was able to find was to combine the two classes. If anyone else finds a better way PLEASE let me know I like to keep my code compartmentalized(or however you spell it).

Thanks again for taking a look at my situation and thank you Richard for your help.

--Steve
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900