首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > PB >

DLL调用解决思路

2013-01-11 
DLL调用本帖最后由 birdw111 于 2011-09-27 13:39:44 编辑.H文件#ifndef dll1_H#define dll1_Hextern C

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" 

热点排行