当一个dll调用另一个dll的功能时,参数值损坏 [英] Parameter values corruption when one dll call a fucntion of another dll

查看:375
本文介绍了当一个dll调用另一个dll的功能时,参数值损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个dll,分别是dll1和dll2
如果我从dll1调用dll2的函数[例如open(string,string)]
-> open("test","1.00");

我崩溃了.
在调试时,我发现在打开功能(字符串str1,字符串str2)中,
str1和str2是垃圾或错误的指针.
所以我崩溃了

如果我尝试从dll2调用dll1函数,也会发生同样的情况

我正在使用loadlibraryA打开dll.

我暂时将函数签名更改为open(char *,char *)

现在工作正常.

任何帮助,为什么我在使用std :: string时会损坏它,以及它如何用于char *.

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*.

推荐答案

请不要在接口中使用stl类模块之间.您的问题可能是您在两个使用不同配置编译的DLL之间进行通信,例如,其中一个使用Debug编译,而另一个使用Release编译.根据您的编译器设置,并定义2个DLL对于相同容器类型(如std :: string)所需的二进制表示形式可能会略有不同.如果您在使用不同设置编译的2个DLL之间进行通信,则可以使用原始类型(如char *),也可以使用自己的容器类型,以确保两种编译器设置都具有相同的内存布局(二进制表示形式).

一些更多的解释来指出我的意思:
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:
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;

...
...
};


@ pasztorpisti:
谢谢,在发布模式下编译了这两个dll,并且Issue得到解决.
@ pasztorpisti :
Thanks ,compiled both dlls in release mode and Issue got resolved.


这篇关于当一个dll调用另一个dll的功能时,参数值损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆