当前位置: 代码迷 >> PB >> DLL调用,该如何处理
  详细解决方案

DLL调用,该如何处理

热度:37   发布时间:2016-04-29 08:33:11.0
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" 
  相关解决方案