简单的动态链接库调用出错了,望高手给予指教。解决方法
简单的动态链接库调用出错了,望高手给予指教。
错误提示:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
------解决方案--------------------
mark
------解决方案--------------------
试试typedef void (__cdecl *GETINFOMATION)(Person* person);
------解决方案--------------------
UP
------解决方案--------------------
把调用申明那里的__stdcall去掉就可以了
------解决方案--------------------
person->address = "CHINA";
person->sex = "男";
person->name = "程辉";
================
这三个指针分配空间了吗?
------解决方案--------------------
http://msdn.microsoft.com/en-us/library/984x0h58(VS.71).aspx
------解决方案--------------------
------解决方案--------------------
- C/C++ code
extern "C" __declspec(dllexport) void GetStruct(Person* person); //dll导出函数声明 //结构体声明 struct Person { char* name; char* sex; char* address; int age; }; //dll导出函数的实现 __declspec(dllexport) void GetStruct(Person* person) { person->address = "CHINA"; person->age = 15; person->sex = "男"; person->name = "程辉"; }
- C/C++ code
//调用DLL代码 //函数指针声明及定义 typedef void (__stdcall *GETINFOMATION)(Person* person); GETINFOMATION Getinfomation; //调用过程 m_hModule = LoadLibraryA("Sun.dll"); if(m_hModule == NULL) { MessageBox(_T("加载动态链接库失败")); } else { Getinfomation = (GETINFOMATION)GetProcAddress(m_hModule,"GetStruct"); } //函数调用 Person person; Getinfomation(&person);
错误提示:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
------解决方案--------------------
mark
------解决方案--------------------
试试typedef void (__cdecl *GETINFOMATION)(Person* person);
------解决方案--------------------
UP
------解决方案--------------------
把调用申明那里的__stdcall去掉就可以了
------解决方案--------------------
person->address = "CHINA";
person->sex = "男";
person->name = "程辉";
================
这三个指针分配空间了吗?
------解决方案--------------------
http://msdn.microsoft.com/en-us/library/984x0h58(VS.71).aspx
------解决方案--------------------
------解决方案--------------------