Sign in to follow this  

Someone help me fix errors?

This topic is 4590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I already opened a few threads askin for help with finding errors but nobody answered/could help me...not even tell me in which .cpp the error could be(which, i think, a few on this forum know). Would somebody look through my whole code? It's not very much...just a simple rendering loop that renders a colorful triangle in 3d space and Directinput(which is new and doesn't work). I also have the suspicion that my code is quite hard to read if i would do a development break and continue in a few months... Probably that someone i'm hoping to find could tell me how i could make my code better, because i'm not very good in c++(i just read a small book with ca 300 pages that told me everything about multithreading,interfaces,inheritance,templates but not what a simple forward decl is :/ ) I want to continue developing my engine but i'm stuck for 2months with that damn compilererrors in d3d9.h and nobody could help me. I don't even know in which .cpp file(s) the error could be :( I just don't know where to begin searching... Can please help me and look through my code? i would zip it and send it per email... regards, m4gnus

Share this post


Link to post
Share on other sites
ok i excluded now my new input part from the build and fixed all other errors...then i included ngInput in my build and now i only have 4 errors :/
but i dunno how i can fix them... it says error @ ngConfig.h: unexpected 'class' 'ngConfig'

ngConfig:

#ifndef NGCONFIG_H
#define NGCONFIG_H



class ngConfig {

public:
ngConfig();
~ngConfig();
void Create(int XRes,int YRes,float FOV);
int m_iXScreenRes;
int m_iYScreenRes;
float m_fFOV;
float m_fAspectRatio;


};

#endif



errors(all related to the one i mentioned i think):
Compiling...
ngInput.cpp
c:\programme\microsoft directx 9.0 sdk (april 2005)\include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800
c:\Dokumente und Einstellungen\gregor\Eigene Dateien\nGin\ngConfig.h(6) : error C2236: unexpected 'class' 'ngConfig'
c:\Dokumente und Einstellungen\gregor\Eigene Dateien\nGin\ngConfig.h(6) : error C2143: syntax error : missing ';' before '{'
c:\Dokumente und Einstellungen\gregor\Eigene Dateien\nGin\ngConfig.h(6) : error C2447: '{' : missing function header (old-style formal list?)
c:\Dokumente und Einstellungen\gregor\Eigene Dateien\nGin\ngEngine.h(28) : error C2061: syntax error : identifier 'ngConfig'


THX coder for the offer...but if someone could finally help me fix this error everything will run fine (i hope)

regards,
m4gnus

Share this post


Link to post
Share on other sites
Quote:
Original post by m4gnus
ok i excluded now my new input part from the build and fixed all other errors...then i included ngInput in my build and now i only have 4 errors :/
but i dunno how i can fix them... it says error @ ngConfig.h: unexpected 'class' 'ngConfig'


Since the class declaration itself is fine, the problem must be in whatever file includes ngConfig.h (i.e. ngInput.cpp). Post that file.

Share this post


Link to post
Share on other sites
ngInput.h includes ngEngine.h which includes ngConfig.h...
ngEngine.h:


#include <windows.h>
//#include <d3dx9.h>
//#include <d3d9.h>
#include "ngConfig.h"
#include "ngCamera.h"
#ifndef NGENGINE_H
#define NGENGINE_H

class ngEngine {
private:

ngCamera *m_pCamera;
float m_fFOV,m_fAspectRatio,m_fNearClip,m_fFarClip;
D3DXMATRIX m_matProj,m_matView,m_matWorld;
D3DXVECTOR3 m_vPos,m_vLookAt,m_vUpVec;
DWORD m_dwFVF;
public:
HWND g_hWindow;
HINSTANCE g_hInst;
//void SendMessage(ngMSG MSG,char *Params);
void SetVF(DWORD FVF);
void SetCamera(ngCamera *Camera);
void render();
ngEngine(); //Constructor
~ngEngine(); //Destructor
bool DoMsgLoop();
void Init(ngConfig cfg);
void Shutdown();


};
#endif


ngInput.h:

//file ngInput.h
#include <DInput.h>
#ifndef NGINPUT_H
#define NGINPUT_H
// #include "ngEngine.h" // auskommentiert
class ngEngine; // fwd-decl.

class ngInput {
private:
ngEngine *m_pEngine;

public:
LPDIRECTINPUT8 m_pDIObj;
LPDIRECTINPUTDEVICE8 g_pSysKeyboard;
void Init(ngEngine *engine);
void GetKeyboardState();
ngInput();
~ngInput();
};

class ngKeyboard {
private:
ngEngine *m_pEngine;
LPDIRECTINPUT8 m_pDIObj;
ngInput *m_pInput;
public:
LPDIRECTINPUTDEVICE8 g_pKeyboard;
void CreateSysKeyboard(ngInput *input,ngEngine *engine);
//void Create(LPDIRECTINPUTDEVICE8 pKeyboard,REFGUID rguid);
bool GetKeyState(int Key);
ngKeyboard();
~ngKeyboard();




}
#endif



ngInput.cpp:

#include "ngInput.h"
#include "ngEngine.h"
#if DIRECTINPUT_VERSION < 0x0800
#if DIRECTINPUT_VERSION < 0x0700
#error "DIRECTINPUT_VERSION < 0x0700"
#else
#error "0x0699 < DIRECTINPUT_VERSION < 0x0800"
#endif
#endif

void ngInput::Init(ngEngine *engine) {
m_pEngine=engine;
DirectInput8Create(m_pEngine->g_hInst,0x0800,IID_IDirectInput8W,(void**)m_pDIObj,NULL);
m_pDIObj->CreateDevice(GUID_SysKeyboard,&g_pSysKeyboard,NULL);
g_pSysKeyboard->SetDataFormat(&c_dfDIKeyboard);
g_pSysKeyboard->SetCooperativeLevel(m_pEngine->g_hWindow,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (g_pSysKeyboard) g_pSysKeyboard->Acquire();

}




void ngInput::GetKeyboardState() {

#define KEYDOWN(name, key) (name[key] & 0x80)

char buffer[256];
HRESULT hr;

hr = g_pSysKeyboard->GetDeviceState(sizeof(buffer),(LPVOID)&buffer);
//if(KEYDOWN(buffer,DIK_ESCAPE) m_pEngine.SendMessage(NGMSG_ESCAPE);

}




ngInput::ngInput() {

}
ngInput::~ngInput() {
}



//***********************************
// NGKEYBOARD
//***********************************
ngKeyboard::ngKeyboard() {
}
ngKeyboard::~ngKeyboard(){
}
bool ngKeyboard::GetKeyState(int Key) {
#define KEYDOWN(name, key) (name[key] & 0x80)
char buffer[256];
g_pKeyboard->GetDeviceState(sizeof(buffer),(LPVOID)&buffer);
if(KEYDOWN(buffer,Key)) return true;


}
void ngKeyboard::CreateSysKeyboard(ngInput *input,ngEngine *engine) {
m_pInput=input;
m_pEngine=engine;
m_pDIObj=m_pInput->m_pDIObj;
m_pDIObj->CreateDevice(GUID_SysKeyboard,&g_pKeyboard,NULL);
g_pKeyboard->SetDataFormat(&c_dfDIKeyboard);
g_pKeyboard->SetCooperativeLevel(m_pEngine->g_hWindow,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (g_pKeyboard) g_pKeyboard->Acquire();
}

/*void ngKeyboard::Create(LPDIRECTINPUTDEVICE8 pKeyboard,REFGUID rguid,ngInput *input,ngEngine) {
m_pInput=input;
m_pDIObj=m_pInput.m_pDIObj;
m_pDIObj->CreateDevice(GUID_SysKeyboard,&g_pKeyboard,NULL);
g_pSysKeyboard->SetDataFormat(&c_dfDIKeyboard);
g_pSysKeyboard->SetCooperativeLevel(m_pEngine->g_hWindow,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (g_pSysKeyboard) g_pKeyboard->Acquire();
}
}*/

[/Source]


regards,
m4gnus

Share this post


Link to post
Share on other sites
next problem:
I got an runtime error(couldn't read 0x00000000 or sth like that).. i know that his is usually caused by a null pointer and i tried if(m_DirectInputobj==NULL)assert(false); //(btw is "if(!m_DirectInputObj).." the same?)
And i got assertion failed so sth must be wrong with DirectInput8Create but i don't know what...
this is how i call it:
DirectInput8Create(m_pEngine->g_hInst,0x0800,IID_IDirectInput8W,(void**)m_pDIObj,NULL);


regards,
m4gnus

Share this post


Link to post
Share on other sites
Quote:
Original post by m4gnus
next problem:
I got an runtime error(couldn't read 0x00000000 or sth like that).. i know that his is usually caused by a null pointer and i tried if(m_DirectInputobj==NULL)assert(false); //(btw is "if(!m_DirectInputObj).." the same?)

Yes, that is the same. The more common way to use an assert is like this, though:

assert (m_DirectInputobj != NULL);

That way, you don't have to remove it later on, as it won't impact release builds.

Quote:

DirectInput8Create(m_pEngine->g_hInst,0x0800,IID_IDirectInput8W,(void**)m_pDIObj,NULL);


Use DIRECTINPUT_VERSION instead of the magic number. Also, are you actually using Unicode? If not, use IID_IDirectInput8W. And finally, use (void **)&m_pDIObj (notice the &-operator).

Share this post


Link to post
Share on other sites
still doesn't work..:( you said i should use IID_IDRECTINPUT8W, but i already use IID_DIRECTINPUT8W i think that's a typo isn't it? But i think that cannot cause the error so one of the other parameters is wrong...btw where is that debug window where all Storage addresses of the Objects are?
Edit: Ok i think something has to be wrong with g_hinst...because everything else looks fine...
Edit2:ok it seems logic that passing an ngEngine pointer that isn't initialised won't work :/ I called input.Init before engine.init everything runs fine now
regards,
m4gnus

Share this post


Link to post
Share on other sites
Quote:
Original post by m4gnus
still doesn't work..:( you said i should use IID_IDRECTINPUT8W, but i already use IID_DIRECTINPUT8W i think that's a typo isn't it?

Yes, it is a typo, I meant IID_DIRECTINPUT8A.


Share this post


Link to post
Share on other sites
Quote:
Original post by Kippesoep
Quote:
Original post by m4gnus
still doesn't work..:( you said i should use IID_IDRECTINPUT8W, but i already use IID_DIRECTINPUT8W i think that's a typo isn't it?

Yes, it is a typo, I meant IID_DIRECTINPUT8A.


Actually, you should just use IID_IDirectInput8 and let the preprocessor figure out which one of the two to use.

Share this post


Link to post
Share on other sites

This topic is 4590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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