
passing std::ofstream by reference to DLL
I am unable to pass an std::ofstream reference to a dll -see example code
below (program crashes at runtime with an unhandled exception). This
appears to be an instance of STL template class members which are not
exported. I have looked at KB Q172396 and KB 168958, but neither seem to
provide a solution to this problem, which must be encountered frequently
(e.g. when overloading operator>> in a dll). Does anyone have some advice?
Thanks in advance.
--
Richard Greenblatt
Source Signal Imaging, Inc.
2323 Broadway, Suite 102, San Diego CA 92102 USA
(voice) +1-619-234-9935 (fax) +1-619-234-9934
(ftp) ftp.cts.com/users/king/s/source[/incoming]
----------------------------------------
// example code
// first a 'local' class that works
#include <fstream>
class CStdtest1 {
public:
void Write(std::ofstream &);
Quote:
};
void
CStdtest1::Write(std::ofstream &fout)
{
fout << 0 << "\n";
Quote:
}
// this is the main program which call the 2 class procedures
int main(int argc, char* argv[])
{
CStdtest MyTestDLL;
CStdtest1 MyTestLocal;
std::ofstream fout("c:\\temp\\stdtest.1");
if (!fout){
std::cout << "File open error.";
} else {
MyTestLocal.Write(fout); // this works
MyTestDLL.Write(fout); // this fails
fout.close();
}
return 0;
Quote:
}
// here is the dll procedure
// This class is exported from the stdtest.dll
// STDTEST_API is defined as __declspec(dllexport)
// or__declspec(dllimport) as appropriate
#include <fstream>
class STDTEST_API CStdtest {
public:
void Write(std::ofstream &);
Quote:
};
void
CStdtest::Write(std::ofstream &fout)
{
fout << 0 << "\n";
Quote:
}