读书人

DLL调用解决思路

发布时间: 2013-01-11 11:57:35 作者: rapoo

DLL调用
本帖最后由 birdw111 于 2011-09-27 13:39:44 编辑 .H文件

#ifndef dll1_H
#define dll1_H
extern "C" int __declspec(dllexport)add(int x,int y);
#endif

.CPP文件
#include "dll1.h"

int add(int x, int y)
{
int m = x + y;
return m;
}


PB中定义:
function int add(int x, int y) library "dll1.dll"

使用:cb_1.clicked:
messagebox('',add(1,2))
错误如下:
---------------------------
PowerBuilder Application Execution Error (R0042)
---------------------------
Application terminated.

Error: Specified argument type differs from required argument type at runtime in DLL function add.
(invalid stack pointer on return from function call) at line 1 in clicked event of object cb_1 of w.
---------------------------
确定
---------------------------
计算机是双核的。
[解决办法]
extern "C" int __declspec(dllexport)add(int x,int y);
改为
extern "C" _declspec(dllexport) int _stdcall add(int x,int y);

另外,PB中定义:
function int add(int x, int y) library "dll1.dll"
改为
function long add(long x, long y) library "dll1.dll"

读书人网 >PB

热点推荐