debug版本的DLL调用release版本的DLL引发的一个问题

stl的常用结构有 vector、list、map等。

今天碰到需要在不同dll间传递这些类型的参数,以void*作为转换参数。

比如 DLL2 的接口 add(void*pVoid);

1.在DLL1中调用该接口,

struct st_headerTerminalRes
{
st_headerTerminalRes(){id=0;}
int id;
int type;//restype 1=mc 2=camera
int resId;
int headerId;
};
typedef vector<st_headerTerminalRes> ltHeaderres;

ltHeaderres ltRes;
add((void*)(&ltRes));

2.在DLL2中

ltHeaderres ltRes = *(ltHeaderres *)pVoid; 在此处报错

如果DLL1和DLL2都是release或都是debug版本,调用是不会报错的。

而本人用的是debug的DLL1,调用release的DLL2。导致在该行报错。

所以在DLL互相调用的时候,一定要统一版本。混合调用很容易出现奇怪的问题。

原文地址:https://www.cnblogs.com/bigfi/p/7122969.html