Hello folks,
I have a C++ Dll , which returns a string . The test application crashes after it displays the string. I have the same problems if I use vector<string> or even if I try to pass the string as reference, although a return type of char* or vector<string>* works fine. Since the dll is to be used with a software that doesn't support pointers, I need a solution that doesn't involve pointers ( and no fixed sized arrays ).
Here is how the code looks like -
#include <string>
#include <vector>
using namespace std ;
and somewhere in the dll code, I have something similar to this -
string xxx( )
{
string str("TestStr" ;
return str ;
}
The test application does the following -
string tt = xxx() ;
cout << tt.c_str() ;
The test application crashes after this and the following dialog box comes -
Debug assertion failed , file dbgheap.c
Expression: _CrtIsValidHeapPointer(pUserData)
I guess this has something to do with both the dll and the test application trying to free memory. Please remember everything works fine if I use pointers.
Is it something to do with the way VC++ implements the STL ?
I would appreciate if anyone could point out what is the problem.
Thanks,
- JJ
I have a C++ Dll , which returns a string . The test application crashes after it displays the string. I have the same problems if I use vector<string> or even if I try to pass the string as reference, although a return type of char* or vector<string>* works fine. Since the dll is to be used with a software that doesn't support pointers, I need a solution that doesn't involve pointers ( and no fixed sized arrays ).
Here is how the code looks like -
#include <string>
#include <vector>
using namespace std ;
and somewhere in the dll code, I have something similar to this -
string xxx( )
{
string str("TestStr" ;
return str ;
}
The test application does the following -
string tt = xxx() ;
cout << tt.c_str() ;
The test application crashes after this and the following dialog box comes -
Debug assertion failed , file dbgheap.c
Expression: _CrtIsValidHeapPointer(pUserData)
I guess this has something to do with both the dll and the test application trying to free memory. Please remember everything works fine if I use pointers.
Is it something to do with the way VC++ implements the STL ?
I would appreciate if anyone could point out what is the problem.
Thanks,
- JJ