Hello,
I am experiencing a strange problem using file streams in a DLL
library. I am using Borland C++ Builder 5.0 Professional and I am
trying to simply read a file using ifstream inside a DLL. However,
after creating the ifstream object I am losing all stack values,
including arguments to the current function and earlier function
calls. The very simple DLL file listing is below:
#include <vcl.h>
#include <windows.h>
#include <iostream.h>
#include <fstream.h>
#pragma hdrstop
#pragma argsused
using namespace std;
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*
lpReserved)
{return 1;}
extern "C" __declspec(dllexport)
void DllRunTest(int a, int b, int c){
int d;
d = a + b + c; // all parameters are correct here
ifstream ifs("C:\\Test.txt"); //try to open file...
d = a + b + c; // random values for a,b,c here
char buffer[100];
ifs >> buffer; // file input works as expected here
// but we can't return to the calling function
// as all function calls that were recorded in the stack are now
gone
// so the program crashes here
}
I attach the generated lib file to a simple application and simply
call the function in DLL when a button is pressed:
extern "C" __declspec(dllimport)
void DllRunTest(int a, int b, int c);
void __fastcall TForm1::Button1Click(TObject *Sender){
DllRunTest(1, 2, 3);
}
Annyone has any ideas how to make ifstreams work correctly in the DLL?
Naturally, the above code works fine when used in a single
application. Any help would be greatly appreciated.
Saulius