I have a mfc projecet and a dll project. My mfc deliver a vector named "out
" to a dll's function.When the dll call out.push_back()
,the system crash. These only occur in release mode,the debug mode work well.The ide is vs2015.
dll.h:
struct dll_param{
int x=0;
}
dll.cpp:
void getParm(vector<dll_param>& out) {
dll_param t;
t.x=10;
out.push_back(t); //crash here
}
dll.def:
LIBRARY "mylib"
DESCRIPTION 'KBhook Windows Dynamic Link Library'
EXPORTS
; Explicit exports can Go here
getParm @1
xxx.cpp from mfc:
HMODULE dll = LoadLibrary(TEXT("mylib.dll"));
typedef void(*Fun1)(vector<dll_param>&);
Fun1 getParm = (Fun1)GetProcAddress(dll, "getParm");
if (getParm) {
vector<dll_param> out;
getParm(out);
}