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

DLL调用,该如何处理

2012-03-16 
DLL调用.H文件C/C++ code#ifndef dll1_H#define dll1_Hextern C int __declspec(dllexport)add(int x,in

DLL调用
.H文件

C/C++ code
#ifndef dll1_H#define dll1_Hextern "C" int __declspec(dllexport)add(int x,int y);#endif

.CPP文件
C/C++ code
#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" 

热点排行