My application is crashing when i am trying to call SetName() in the below code.
main.cpp
using namespace std;
int main()
{
Schema * schemaExp = new Schema();
//Application is getting crash when calling this function
schemaExp -> SetName("ExpSchema");
string srctable;
srctable=schemaExp->GetName();
cout <<"\nConnection EXPORT using the target table:" << srctable.c_str() << endl;
delete schemaExp;
return 0;
}
Schema Class Definition:
using namespace std;
class Schema
{
public:
TELAPI_EXPORT void SetName(string name);
TELAPI_EXPORT string GetName();
protected:
string tableName;
};
void Schema::SetName(string name){ tableName = name; }
string Schema::GetName()
{
return tableName;
}
I am using MSVS 9 (VS 2008). My application as well as shared library(dll)(I am using to link with my application) is also of c++ environment.Now observe the below cases:
1.when the shared library/dll is built in Debug mode and my application is also built in Debug mode Result: Application executed successfully
2.when the shared library/dll is built in Release mode and my application is also built in Release mode Result: Application executed successfully
3.when the shared library/dll is built in Release mode and my application is built in Debug mode Result:Application throws a crash report with following break statement.
Unhandled exception at 0x1003f3a5 in multiple.exe: 0xC0000005: Access violation reading location 0x00134000.
Note: The above code is just a part from my application. Schema Class Definition is from shared library and main.cpp from my application. Also, this problem seems to fail on Windows only, unix versions worked fine.
One more important thing if I comment out schemaExp -> SetName("ExpSchema");
in main.cpp , the application passes in the above three cases, I mean any combination of release and debug build
In the entire code of my original application(of which above code is a part), only the above function call is troubling me
I guess something going wrong in using string as a parameter to function call, but also note when I wrote the sample program(not linking to shared library/dll) implementing the above scenario my application runs fine
Completely struck over here. Unable to predict what's going wrong and what's causing access violation that too only in the #3 case.
Please help me in fixing this problem. Any kind of help is greatly appreciated.
Thanks in advance.