Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

zackriggle

stupid dll's and ofstream

This topic is 5519 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

does the fstream class have any specific issues when used with a dll? here is some code that reproduces the error:
  
//

//:::::::::::::::::::::::::

//      TESTDLL.H

//:::::::::::::::::::::::::

//

#include <fstream.h>
#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dllexport)
#else
#define TESTDLL_API __declspec(dllimport)
#endif

// This class is exported from the TestDLL.dll

class Debugger
{
public:
	TESTDLL_API Debugger(void);
	TESTDLL_API ~Debugger(void);
	TESTDLL_API void AddError(char loc_error[], char error_message[], DWORD error_number);
	TESTDLL_API void AddError(char error_message[], DWORD error_number);
	TESTDLL_API void Add(char message[]);
	ofstream	debugfile;
};



//

//:::::::::::::::::::::::::

//     TESTDLL.CPP

//:::::::::::::::::::::::::

//

#define TESTDLL_EXPORTS
#include <fstream.h>
#include "testdll.h"
TESTDLL_API Debugger::Debugger()
{
	debugfile.open("test.txt");
};
TESTDLL_API Debugger::~Debugger()
{
	debugfile.close();
};
TESTDLL_API void Debugger::AddError( char loc_error[], char error_message[], DWORD error_number)
{
	debugfile << "### Error ###";
		debugfile << endl;
	debugfile << "Location: ";
		debugfile << loc_error;
		debugfile << endl;
	debugfile << "Description: ";
		debugfile << error_message ;
		debugfile << endl;
	debugfile << "Erro Number: " ;
		debugfile << error_number ;
		debugfile << endl;
	debugfile << endl;
};
TESTDLL_API void Debugger::AddError(char* error_message, DWORD error_number)
{
	debugfile << " ### Error ###\n";
	debugfile << "Description: " << error_message << endl;
	debugfile << "Erro Number: " << error_number << endl;
	debugfile << endl;
};
TESTDLL_API void Debugger::Add(char* message)
{
	debugfile << " ### Other ###\n" << message << endl;
	debugfile << endl;
};


/*
    Compile testdll.cpp as a DLL file.
*/



//

//:::::::::::::::::::::::::

//     TEST.CPP

//:::::::::::::::::::::::::

//  Compile this as an executeable file....

//  Include testdll.lib


#include <fstream.h>
int main()
{ 
     Debugger dbg;
     dbg.Add("TEST!");
};

  
And you get some bullshit error... I wrote this code on the fly so it may have some compile errors. I have it so that it compiles fine, but is part of a larger project so i did not include all of the code. If there are some compile errors, just fix them real quick... ================== My (soon-to-be) Cherished Cookie of Appreciation: -- MattB - for WinSock advice --

Share this post


Link to post
Share on other sites
Advertisement
Ah! Sorry, I forgot I always use -DNO_BULL_WARN so I never get those.

Share this post


Link to post
Share on other sites
You''re probably using the wrong version of the runtime library. I think you need to link with the multithreaded dll version (someone correct me if I''m off here, I''m no dll/multithreading expert). Usually choosing the library is done via a compiler switch, or if you''re using an IDE like Visual C++ it''s probably an option somewhere in the project settings. The options will be like:

single threaded
multi threaded dll
single threaded debug
multi threaded dll debug

Share this post


Link to post
Share on other sites
Use the standard #include <fstream> instead of the deprecated #include <fstream.h>.

You don''t need all those TESTDLL_API, you only need one at the top of the class:

  
class TESTDLL_API Debugger
{
public:
Debugger();
...
};


Check the runtime library you are using (as Dobbs said).

What _exactly_ are the error message you get?



Update GameDev.net system time campaign - success at last

Share this post


Link to post
Share on other sites
when using an fstream or stl vector/ect in a dll, you should still get a warning (4215 if im not mistaken).. but it should still compile fine. if im understanding you correctly, you''re getting a runtime error?

-eldee
;another space monkey;
[ Forced Evolution Studios ]


::evolve::

Do NOT let Dr. Mario touch your genitals. He is not a real doctor!

Share this post


Link to post
Share on other sites
quote:
Original post by eldee
you should still get a warning (4215 if im not mistaken

Compiler Warning (level 1) C4215 - nonstandard extension used : long float?



Update GameDev.net system time campaign - success at last

Share this post


Link to post
Share on other sites
as Dobbs said, the usual cause of weird runtime errors when you move things to Dlls is that your Dlls and project are not set to use the same runtime library ... under Visual C++, go to project settings/properties for both your Dll and you Application and check that "C++/CodeGenerattion/Runtime Library" for both the Dll and App are the same (each debug should match, and each release version too ... and if you are using something like the SDL or Xerces-C binary release then they MUST be Multithreaded Dll versions).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!