Sign in to follow this  
Plasmarobo

Include file iffy....

Recommended Posts

For some reason windows does not want to let me use my custom Graphics thing. It is incomplete, but I want to test a feature before I finish it. My main object doesn't exist aparently. I have check for syntax, but I am not the best a grammer or anykind. Basically I am asking for how I get this to work (Uses Direct 3D and Windows) I am using Dev C++ WinMain:


#include <windows.h>
#include "Direct.h"


eGraphics Gengine;
Gengine.SaveSettings("config.txt");
Gengine.LoadSettings("config.txt");
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "Test of Chronicles SDK";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Test for CSDK",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           Gengine.Present.Width,                 /* The programs width */
           Gengine.Present.Height,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);
bool game_active = true;

while(game_active)
{
    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }
    
}
    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

the H file:
//Direct.h
//This file will have our interface to Direct X graphics.
//Chronicles 2 may use OGRE, but for now, Direct X must suffice.
//Austen Higgins-Cassidy
// 4/16/2006


//Include Direct X files
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <string>
#include <vector>
#include <dplay8.h>
#include <dpaddr.h>
#include <dinput.h>
#include <stdio.h>
#pragma comment(lib,"d3d9.h")
#pragma comment(lib,"d3dx9.h")
#pragma comment(lib,"dplay8.h")
#pragma comment(lib,"dpaddr.h")
#pragma comment(lib,"dinput.h")


#ifndef _DIRECT_H_
#define _DIRECT_H_
//Setup a graphic struct
extern IDirect3D9 *iDirectX;
extern IDirect3DDevice9 *iD3DDevice;

//2-D graphics


//3-D graphics


//Setup Class

class eGraphics
{
     D3DPRESENT_PARAMETERS Present;
     D3DDISPLAYMODE Display;
      std:vector<D3DVERTEXBUFFER> Buffers;
public:
       eGraphics();
       ~eGraphics();
       
       bool Init(std::string fname);
       bool LoadSettings(ostream& fOut);
       bool SaveSettings(istream& fIn);
       bool LoadMesh(std::string fname);
       bool LoadGraphic(std::string fname);
       bool Render();
       bool Update();
       bool Recover();
       bool Destroy();
       
       
};
#endif

and cpp file
//Expantions for Direct.h

//include files
#include <windows.h>
#include "Direct.h"

#include <d3d9.h>
#include <d3dx9.h>
#include <string>
#inculde <vector>
#include <dplay8.h>
#include <dpaddr.h>
#include <dinput.h>

#include <stdio.h>


using namespace std;

IDirect3D9 *iDirectX;
IDirect3DDevice9 *iD3DDevice;

eGraphics::eGraphics()
{
                 
}

eGraphics::~eGraphics()
{

}

bool eGraphics::Init(string fname)
{       
/* ifstream fobj;
		fobj.open(fname.c_str());
		if(fobj.fail() || !fobj.is_open())
			return false;
LoadSettings(fobj);
fobj.close();
*/

if((iDirectX = Direct3DCreate9(D3D_SDK_VERSION)) ==NULL)
return false;


Display.Width = 1200;
Display.Height = 800;
Display.RefreshRate = 0;
Display.Format = D3DFMT_A8R8G8B8;

if(FAILED(iDirectX->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Display.Format, Display.Format, false)))
return false;
ZeroMemory( &Present, sizeof(Present) );

Present.Windowed = false;
Present.SwapEffect = D3DSWAPEFFECT_FLIP;
Present.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
Present.PresentationInterval = D3DPRESENT_INVERVAL_DEFAULT;
Present.BackBufferFromat = Display.Format;
Present.BackBufferWidth = Display.Width;
Present.BackBufferHeight = Display.Height;

if(FAILED(iDirectX->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, 
                                                     D3DCREATE_SOFTWARE_VERTEXPROCESSING, 
                                                     &Present, &iD3DDevice)))
return false;
//Open file and save
ofstream fobj;
fobj.open(fname.c_str());
		if(fobj.fail() || !fobj.is_open())
			return false;
SaveSettings(fobj);


}

bool eGraphics::Recover()
{
     //call this when device is lost
     iDirectX->Release(); // release COM
     iD3DDevice->Reset(&Present);
    LoadSettings(); //reload settings
     Init(); // Initilize again
     return true;
}

bool Destroy()
{
     //release COM objects for the graphics and zero memory of the other things
iDirectX->Release();
iD3DDevice->Release();
ZeroMemory( &Present, sizeof(Present));
ZeroMemory(&Display, sizeof(Display));
return true;
}

bool eGraphics::Render()
{
     return false;
}
 
bool eGraphics::Update()
{
     return false;
}

bool eGraphics::LoadMesh(std::string fname)
{
     return false;
}

bool eGraphics::LoadGraphic(std::string fname)
{
     return false;
}

bool eGraphics::LoadSettings(ifstream& fIn)
{
     string hold; // set a temp holding string
	
if(!getline(fIn, hold)) //Ignore names
        return false;
fIn >> Display.Width; // get data
if(!getline(fIn, hold))
        return false;
fIn >> Display.Height;
if(!getline(fIn, hold))
        return false;
fIn >> Display.RefreshRate;
if(!getline(fIn, hold))
        return false;
fIn >> Display.Format;
if(!getline(fIn, hold))
        return false;
fIn >> Present.Windowed;
if(!getline(fIn, hold))
        return false;
fIn >> Present.SwapEffect;
if(!getline(fIn, hold))
        return false;
fIn >> Present.FullScreen_RefreshRateInHz;
if(!getline(fIn, hold))
        return false;
fIn >> Present.PresentationInterval;
if(!getline(fIn, hold))
        return false;
fIn >> Present.BackBufferFormat;
if(!getline(fIn, hold))
        return false;
fIn >> Present.BackBufferWidth;
if(!getline(fIn, hold))
        return false;
fIn >> Present.BackBufferHeight;

return true;
}

bool eGraphics::SaveSettings(ofstream& fOut)
{
     //send setting data to fOut stream  
fOut << "Width\n";		
fOut << Display.Width << endl;
fOut << "Height\n";
fOut << Display.Height << endl;
fOut << "Refresh Rate\n";
fOut << Display.RefreshRate << endl;
fOut << "Color Format\n";
fOut << Display.Format << endl;
fOut << "Windowed \n";
fOut << Present.Windowed << endl;
fOut << "Swap Effect \n";
fOut << Present.SwapEffect << endl;
fOut << "Full Screen Refresh Rate\n";
fOut << Present.FullScreen_RefreshRateInHz << endl;
fOut << "Presentation Interval\n";
fOut << Present.PresentationInterval << endl;
fOut << "Back Buffer Format\n";
fOut << Present.BackBufferFormat << endl;
fOut << "Back Buffer Width \n";
fOut << Present.BackBufferWidth << endl;
fOut << "Back Buffer Height\n";
fOut << Present.BackBufferHeight << endl;


}

and my compile log:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\projects\Chronicles\Media\Makefile.win"
Executing  make...
make.exe -f "C:\Dev-Cpp\projects\Chronicles\Media\Makefile.win" all
g++.exe -c ../../../Templates/WinMain.cpp -o ../../../Templates/WinMain.o -I"lib/gcc/mingw32/3.4.2/include"  -I"include/c++/3.4.2/backward"  -I"include/c++/3.4.2/mingw32"  -I"include/c++/3.4.2"  -I"include"  -I"C:/DX90SDK/Include"  -I"C:/DX90SDK/Include"    -ansi -fexpensive-optimizations

../../../Templates/WinMain.cpp:7: error: `eGraphics' does not name a type
../../../Templates/WinMain.cpp:8: error: expected constructor, destructor, or type conversion before '.' token
../../../Templates/WinMain.cpp:8: error: expected `,' or `;' before '.' token
../../../Templates/WinMain.cpp:9: error: expected constructor, destructor, or type conversion before '.' token
../../../Templates/WinMain.cpp:9: error: expected `,' or `;' before '.' token

../../../Templates/WinMain.cpp: In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
../../../Templates/WinMain.cpp:55: error: `Gengine' undeclared (first use this function)
../../../Templates/WinMain.cpp:55: error: (Each undeclared identifier is reported only once for each function it appears in.)

make.exe: *** [../../../Templates/WinMain.o] Error 1

Execution terminated

[Edited by - Plasmarobo on April 23, 2006 2:38:47 PM]

Share this post


Link to post
Share on other sites
I haven't read the whole thing yet, but in your header you might as well put the include guard at the top. I think you should put

IDirect3D9 *iDirectX;
IDirect3DDevice9 *iD3DDevice;

into the Direct.cpp

and

extern IDirect3D9 *iDirectX;
extern IDirect3DDevice9 *iD3DDevice;

into Direct.h

Correct me if I'm wrong.

#inculde <vector> [smile]

Share this post


Link to post
Share on other sites
Never trash and restart a project because you can't figure out what is wrong. You will learn nothing from that, gain nothing, and probably make the same mistakes again.

Here's something I noticed:

eGraphics Gengine;
Gengine.SaveSettings("config.txt");
Gengine.LoadSettings("config.txt");


You're calling functions (SaveSettings and LoadSettings) outside of any block (i.e., not inside a {} pair). You can't do that. You're also calling these functions with string parameters but they expect stream references; that's not going to work either (I'm pretty sure the string-parameter cts in the stream classes are declared explicit).

The first error sounds like it doesn't recognize the eGraphics type, but the class declaration for eGraphics looks sane at a quick glance.

As a stylistic aside unrelated to your problem, you'll probably want to remove extraneous #include directives from Direct.h (only #include exactly what you need) and move the #include directives inside the #ifndef guards). The comment pragmas should probably be moved to a source file as well, otherwise you'll cause anything that uses Direct.h to link with the specified libraries which may be undesirable. Also, the format of the comment pragmas is incorrect anyway (the string parameter should reference a library name not a header file, at least in Visual Studio -- which reminds me you appear to be using Dev-C++ or another IDE that uses a version of GCC to compile and which may not support #pragma comment (if it doesn't, standard compliant behavior is to silent ignore the pragma -- that is, it won't link and and it won't tell you it has done so).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this