/**************************************************************************************************
filename: S_CErrorHandler.h
date: 22/Oct/2000.
author: Bernardo Quiroga.
contact at: bernardo_quiroga@hotmail.com, ICQ UIN: 13639620.
website: http://www.casema.net/~drago/projects/symbiotic/index.html
-----------------------------------------------------------------------------------------------
This file is part of "Symbiont", the Game Engine part of The Symbiotic Engine.
This class handles any error that might pop up.
**************************************************************************************************/
#ifndef __S_CERRORHANDLER_H__
#define __S_CERRORHANDLER_H__
///////////////////////////////////////////////////////////////////////////////////////////////////
// Definitions
#define S_EH_LOG_FILE_NAME "error.log"
///////////////////////////////////////////////////////////////////////////////////////////////////
// Class S_CErrorHandler
class S_INTERFACE S_CErrorHandler
{
public:
S_CErrorHandler();
S_CErrorHandler(const string& strLogFilename);
virtual ~S_CErrorHandler();
void Process(const string& strFilename, const uint& nLine);
void Reset();
static void SetError(const string& strErrorMessage);
private:
void Log(const string& strFilename, const uint& nLine);
void ShowErrorDialog();
protected:
int m_nInitialized;
static string m_strErrorMessage;
string m_strLogFilename;
};
#endif // __S_CERRORHANDLER_H__
///////////////////////////////////////////////////////////////////////////////////////////////////
// S_CErrorHandler.h - End of file.
///////////////////////////////////////////////////////////////////////////////////////////////////
/**************************************************************************************************
filename: S_CErrorHandler.cpp
date: 22/Oct/2000.
author: Bernardo Quiroga.
contact at: bernardo_quiroga@hotmail.com, ICQ UIN: 13639620.
website: http://www.casema.net/~drago/projects/symbiotic/index.html
-----------------------------------------------------------------------------------------------
This file is part of "Symbiont", the Game Engine part of The Symbiotic Engine.
This class handles any error that might pop up.
**************************************************************************************************/
///////////////////////////////////////////////////////////////////////////////////////////////////
// Includes
#include "Symbiont.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// Static data declaration.
string S_CErrorHandler::m_strErrorMessage = "0";
///////////////////////////////////////////////////////////////////////////////////////////////////
// S_CErrorHandler::S_CErrorHandler()
/////////////////////////////////////
// Default class constructor.
S_CErrorHandler::S_CErrorHandler() : m_strLogFilename(S_EH_LOG_FILE_NAME)
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// S_CErrorHandler::S_CErrorHandler(...)
////////////////////////////////////////
// Class constructor.
S_CErrorHandler::S_CErrorHandler(const string& strLogFilename)
{
// Set the error log''s filename. To which the errors logged will be saved.
m_strLogFilename = strLogFilename;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// S_CErrorHandler::~S_CErrorHandler()
//////////////////////////////////////
// If the error message wasn''t processed, it will be reset at object destruction.
S_CErrorHandler::~S_CErrorHandler()
{
// Delete the error message.
Reset();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// void S_CErrorHandler:<img src="tongue.gif" width=15 height=15 align=middle>rocess(...)
/////////////////////////////////////
// Processes the error, log''s the error message on disk and shuts down the program showing an error
// dialog box.
void S_CErrorHandler:<img src="tongue.gif" width=15 height=15 align=middle>rocess(const string& strFilename, const uint& nLine)
{
// Check if an error has been registered.
if(m_strErrorMessage != "0")
{
// Log the error.
Log(strFilename, nLine);
// Show the error dialog box.
ShowErrorDialog();
// Reset the error.
Reset();
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// void S_CErrorHandler::Log(...)
/////////////////////////////////
// Log the error to disk. Stating the time of occurance and the error message.
void S_CErrorHandler::Log(const string& strFilename, const uint& nLine)
{
// Create the error log, or overwrite it.
FILE* pLogFile = fopen(m_strLogFilename.c_str(), "w");
// Retrieve the current date and time.
char szDate[16], szTime[16];
_strdate(szDate); _strtime(szTime);
// Print the log''s header.
fprintf(pLogFile, "///////////////////////////////////////////////////////////////////////////////////////////////////\n");
fprintf(pLogFile, "//\tFilename:\t%s\n", m_strLogFilename.c_str());
fprintf(pLogFile, "//\tDate:\t\t%s, %s\n", szDate, szTime);
fprintf(pLogFile, "//\tAuthor:\t\tBernardo Quiroga - Symbiotic Engine (Symbiont)\n");
fprintf(pLogFile, "//\tE-mail:\t\tbernardo_quiroga@hotmail.com\n");
fprintf(pLogFile, "//\tICQ UIN:\t13639620\n");
fprintf(pLogFile, "//\n");
fprintf(pLogFile, "//\tThis is the error log, it contains the errors that the program encountered. Contact me\n");
fprintf(pLogFile, "//\t(via e-mail or ICQ) so that I can solve the problem.\n");
fprintf(pLogFile, "///////////////////////////////////////////////////////////////////////////////////////////////////\n\n");
// Log the error. First the filename and the line number the error was encountered, then the
// error message.
fprintf(pLogFile, "Error encountered in file:\t\"%s\"\n", strFilename.c_str());
fprintf(pLogFile, " at line:\t\"%d\"\n", nLine);
fprintf(pLogFile, "With the error message:\t\t\"%s\"", m_strErrorMessage.c_str());
// Close the log file.
fclose(pLogFile);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// void S_CErrorHandler::ShowErrorDialog()
//////////////////////////////////////////
// Show the error message in a dialog box, whereafter (after pressing OK) the program shuts down.
void S_CErrorHandler::ShowErrorDialog()
{
// Copy the error message to the dialog message and add a referral to the log file.
string strDialogMessage = m_strErrorMessage;
strDialogMessage += "\nSee the log file for additional information.";
// Show the error dialog box and shut down the program.
MessageBox(NULL, strDialogMessage.c_str(), NULL, MB_OK | MB_ICONERROR | MB_SYSTEMMODAL | MB_TOPMOST);
PostQuitMessage(0);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// void S_CErrorHandler::Reset()
////////////////////////////////
// Flush the error register, so that the error that was registered as last will be ignored.
void S_CErrorHandler::Reset()
{
// Reset the error message.
m_strErrorMessage = "0";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// void S_CErrorHandler::SetError(...)
//////////////////////////////////////
// Register an error and set the error message.
void S_CErrorHandler::SetError(const string& strErrorMessage)
{
// Copy the new error message.
m_strErrorMessage = strErrorMessage;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// S_CErrorHandler.cpp - End of file.
///////////////////////////////////////////////////////////////////////////////////////////////////
----------
Mail me, Drago's OpenGL Website
STL strings
I''m hoping that you can take a quick peak at the code listed below and tell me if you detected any errors, because it just won''t work :-(. If I replace all the STL string objects with char* (not literally ofcourse) than everything''s just fine and the code does what it''s supposed to do, but now it will compile and does work but it also gives weird kernel32.dll critical errors at run-time.
osu!
Looks fine to me. I wouldn''t set the default error message to "0" if I were you; rather, I''d leave it empty, and check whether it was empty (bool basic_string::empty ()) to see if there were errors.
I don''t see your includes, so are you "using namespace std;"? Do you get any compile-time errors or warnings (at warning level 3)? Have you stepped through the code and noted the line at which the error occurs?
I don''t see your includes, so are you "using namespace std;"? Do you get any compile-time errors or warnings (at warning level 3)? Have you stepped through the code and noted the line at which the error occurs?
if you are using STL for strings, why not use STL for file i/o, and use std::ofstream instead of fprintf() ?
-- Rocky
I included: and am: "using namespace std" as well. This is the compiler error MSVC6 gives me: "d:\programming files\current projects\symbiotic engine\symbiont\source files\s_cerrorhandler.h(37) : warning C4251: ''m_strErrorMessage'' : class ''std::basic_string,class std::allocator >'' needs to have dll-interface to be used by clients of class ''S_CErrorHandler''". When I compile using the Intel Compiler (version 4.0) I don''t get any errors.
rpully: this is my first shot at STL when I get the strings working I''ll change the code to use STL for file i/o, okey ;-).
----------
Mail me, Drago's OpenGL Website
rpully: this is my first shot at STL when I get the strings working I''ll change the code to use STL for file i/o, okey ;-).
----------
Mail me, Drago's OpenGL Website
osu!
Hm, sounds like you''re mixing statically-linked and non-statically-linked libraries. Look at your code generation. I''m not too swift on the DLL front, so probably others can give you more info, but this definitely looks like a linkage problem (i.e. it has nothing to do with your source code).
This is how MSVC6 explains the error code:
Compiler Warning (level 1) C4251
''identifier'' : class ''type'' needs to have dll-interface to be used by clients of class ''type2''
The specified base class was not declared with the __declspec(dllexport) keyword.
A base class or structure must be declared with the __declspec(dllexport) keyword if a function in a derived class is to be exported.
If I understand it correctly I must "dllexport" the basic_string STL class, which I simply cannot do. So I probably don''t understand the error code''s explanation. S_INTERFACE takes care of dllexport/dllimport for S_CErrorHandler so I don''t know what MSVC means ..
----------
Mail me, Drago's OpenGL Website
Compiler Warning (level 1) C4251
''identifier'' : class ''type'' needs to have dll-interface to be used by clients of class ''type2''
The specified base class was not declared with the __declspec(dllexport) keyword.
A base class or structure must be declared with the __declspec(dllexport) keyword if a function in a derived class is to be exported.
If I understand it correctly I must "dllexport" the basic_string STL class, which I simply cannot do. So I probably don''t understand the error code''s explanation. S_INTERFACE takes care of dllexport/dllimport for S_CErrorHandler so I don''t know what MSVC means ..
----------
Mail me, Drago's OpenGL Website
osu!
The thing is that I can use this S_CErrorHandler class as if everything would be okey, but when I delete the object the run-time error occurs. And the strangest thing is that every class from my dll has this error, even if they don''t use the STL string .
----------
Mail me, Drago's OpenGL Website
----------
Mail me, Drago's OpenGL Website
osu!
I statically link STL libraries all the time, so it''s possible. We also have several DLLs who use it. It looks like you''re telling the compiler to use the DLL version of the standard libraries, but it''s linking in the wrong files for some reason. Again, look at Project->Settings->C/C++->Code Generation, make sure that''s set to what you want.
If you were to start up a new project and create a simple program using std::string, I guarantee you it''d work fine. Something is weird in your compiler or linker options that''s screwing up STL. Maybe you should start a new project, then copy your source files over & try compiling that way.
If you were to start up a new project and create a simple program using std::string, I guarantee you it''d work fine. Something is weird in your compiler or linker options that''s screwing up STL. Maybe you should start a new project, then copy your source files over & try compiling that way.
Stoffel: I did as you said, I created a new project and build it, but MSVC still gives the warning . And I never changed anything in "Project->Settings->C/C++->Code Generation" These are the settings (for Win32 Debug):
Processor: Blend*
Use run-time library: Debug Multithreaded
Calling convention: __cdecl*
Struct member alignment: 8 bytes*
Project Options:
/nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_SYMBIONT" /Fp"Debug/Symbiont.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
----------
Mail me, Drago's OpenGL Website
Processor: Blend*
Use run-time library: Debug Multithreaded
Calling convention: __cdecl*
Struct member alignment: 8 bytes*
Project Options:
/nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_SYMBIONT" /Fp"Debug/Symbiont.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
----------
Mail me, Drago's OpenGL Website
osu!
I solved the problem :D! Thanks to Stoffel''s advice I started "messing" around with the Code Generation panel. When I had rebuild everything with Debug Multithreaded DLL on instead of just Debug Multithreaded, no errors were reported! Finally, I can continue on...
----------
Mail me, Drago's OpenGL Website
----------
Mail me, Drago's OpenGL Website
osu!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement