Program crashes
-
Hi! I have a problem calling a function defined in a dll, like this:
__declspec( dllexport ) __int8 __cdecl freadCharacter( istream &inputStream, char &destinationCharacter ) { inputStream >> resetiosflags( ios::skipws ) >> destinationCharacter; inputStream >> setiosflags( ios::skipws ); if ( inputStream.bad( ) ) return 0; return 1; }
In the program that uses the dll, I call the function in this manner:
char c; ifstream src( "input.dat" ); if ( !src ) { cerr << "Error opening file input.dat\n" << flush; exit( EXIT_FAILURE ); } freadCharacter( src, c );
When I run the program, it crashes. It crashes exactly when trying to execute this line:
inputStream >> resetiosflags( ios::skipws ) >> destinationCharacter;
Can anybody help me by telling what is wrong with my code? Is it a real problem that I call a function defined in a dll which takes a reference to
istream
as a parameter? I'm asking this because if I define the function in my application, it works perfectly. Thanks in advance! -
Hi! I have a problem calling a function defined in a dll, like this:
__declspec( dllexport ) __int8 __cdecl freadCharacter( istream &inputStream, char &destinationCharacter ) { inputStream >> resetiosflags( ios::skipws ) >> destinationCharacter; inputStream >> setiosflags( ios::skipws ); if ( inputStream.bad( ) ) return 0; return 1; }
In the program that uses the dll, I call the function in this manner:
char c; ifstream src( "input.dat" ); if ( !src ) { cerr << "Error opening file input.dat\n" << flush; exit( EXIT_FAILURE ); } freadCharacter( src, c );
When I run the program, it crashes. It crashes exactly when trying to execute this line:
inputStream >> resetiosflags( ios::skipws ) >> destinationCharacter;
Can anybody help me by telling what is wrong with my code? Is it a real problem that I call a function defined in a dll which takes a reference to
istream
as a parameter? I'm asking this because if I define the function in my application, it works perfectly. Thanks in advance!I would have needed to run some tests, but it may have to do with the fact that the source contains more than one character. I would change the second parameter from a character type to a string type and see what happens. I dought that will work, because it works in your application. That said, it is where I would start. How badly does the program crash? Can you give an error number? It has been a while since I created a DLL, but I looked up the specs and did not see anything wrong. I do not see a return type specified for "freadCharacter", but the compiler would scream if that was missing in the actual code.
Eikthrynir wrote:
Is it a real problem that I call a function defined in a dll which takes a reference to istream as a parameter?
I can think of no reason why that would cause a problem. INTP Every thing is relative...
-
I would have needed to run some tests, but it may have to do with the fact that the source contains more than one character. I would change the second parameter from a character type to a string type and see what happens. I dought that will work, because it works in your application. That said, it is where I would start. How badly does the program crash? Can you give an error number? It has been a while since I created a DLL, but I looked up the specs and did not see anything wrong. I do not see a return type specified for "freadCharacter", but the compiler would scream if that was missing in the actual code.
Eikthrynir wrote:
Is it a real problem that I call a function defined in a dll which takes a reference to istream as a parameter?
I can think of no reason why that would cause a problem. INTP Every thing is relative...
I run my program under Windows XP Professional. When it crashes, Windows doesn't show me any run-time error number. It just tells me something like this: "Test.exe has encountered a problem and needs to close. We are sorry for the inconvenience." It's the standard Windows message which appears at every program crash. I have tried even to change the second parameter of freadCharacter into an
int
. I get the same run-time error. I have tested infreadCharacter
whetherinputStream
is open and it is. I thought that maybe that is my problem, but it's not. Thanks! -
I run my program under Windows XP Professional. When it crashes, Windows doesn't show me any run-time error number. It just tells me something like this: "Test.exe has encountered a problem and needs to close. We are sorry for the inconvenience." It's the standard Windows message which appears at every program crash. I have tried even to change the second parameter of freadCharacter into an
int
. I get the same run-time error. I have tested infreadCharacter
whetherinputStream
is open and it is. I thought that maybe that is my problem, but it's not. Thanks!I have no idea what the problem is, but I can give you the name of the best book I know of. Programming Applicationtions for Microsoft Windows By Jeffrey Richter. I consider Jeffrey Richter a master Windows Guru, he has even taught people at Microsoft on the subject. I do not know if he has written anything directly related to C++ (where I think your problem may lay), but search for his name. Sorry that I did not have time to investigate this furthur myself. John R. Shaw INTP Every thing is relative...
-
I have no idea what the problem is, but I can give you the name of the best book I know of. Programming Applicationtions for Microsoft Windows By Jeffrey Richter. I consider Jeffrey Richter a master Windows Guru, he has even taught people at Microsoft on the subject. I do not know if he has written anything directly related to C++ (where I think your problem may lay), but search for his name. Sorry that I did not have time to investigate this furthur myself. John R. Shaw INTP Every thing is relative...
I really appreciate and thank you for the time spent in helping me solve this problem. I will search for Mr. Jeffrey Richter's book. Thanks again!