Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have two dll say dll1 and dll2
if I call a function of dll2[say open(string,string)] from dll1
->open("test","1.00");

I'm getting a crash.
On debugging I found that in the fucntion open(string str1,string str2)
str1 and str2 are garbage or bad pointer.
so I'm getting a crash

Same is happening if I'm trying to call dll1 function from dll2

I'm using loadlibraryA to open dlls.

For time being I have changed the function signature as open(char*, char*)

and now it is working fine.

Any help why it is getting corrupted when I', using std::string and how come it is working for char*.
Posted

Never use stl classes in interfaces between modules. Your problem is probably that you communicated between 2 DLLs that were compiled with different configurations, for example one of them compiled using Debug and the other with Release. Depending on your compiler settings and defines the binary representation expected by the 2 DLLs for the same container type (like std::string) might differ slightly. If you communicate between 2 DLLs compiled with different settings then either use primitive types (like char*) or your own container types that are guaranteed to have the same memory layout (binary representation) with both compiler settings.

Some more explanation to point you out what I mean:
C++
class CMyString
{
...
...

private:
// Guess what happens if you try to pass a CMyString instance between 2 DLLs
// when one of them is compiled with Debug and the other with Release...
#ifdef _DEBUG
    array<iterator> m_DebugIteratorList;
#endif

    char* m_Buffer;

...
...
};
 
Share this answer
 
v2
@ pasztorpisti :
Thanks ,compiled both dlls in release mode and Issue got resolved.
 
Share this answer
 
v2
Comments
pasztorpisti 10-Oct-12 7:27am    
You are welcome! :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900