PB如何调用dll中的函数?

luomario 2002-12-18 09:55:58
我用VC在DLL中定义了这样一个函数:
long lTest(float f_in, char *s_in, float f_out, long l_out, char *s_out)
其中,f_in、s_in为输入参数,其他为输出参数。

请问:我在PB中应该这样声明和调用?

我是这样用的:
声明:
FUNCTION long lTest(decimal f_in, string s_in, ref decimal f_out, ref long l_out, ref string s_out) LIBRARY "dlltest.DLL"
调用:
decimal lf_in=100.00, lf_out
string ls_in="123", ls_out
long ll_out, ll_rc
ll_rc = lTest(lf_in, ls_in, lf_out, ll_out, ls_out)
在程序执行中报错:
Error:specified argument type differs from required argument type at runtime in DLL function lTest.(invalid stack pointer on return from function call)
我错在哪里?
...全文
449 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
luomario 2003-01-06
  • 打赏
  • 举报
回复
extern "C" 是什么意思?
_declspec(dllexport) 是什么意思?
WINAPI 是什么意思?
为什么要在.def中加上要导出的函数?
jhl_hong 2003-01-06
  • 打赏
  • 举报
回复
如果你没有在.def中没有导出pb 是无法正确使用的
luomario 2003-01-03
  • 打赏
  • 举报
回复
to toutou:
为何输入参数s_in在声明时也要加ref?
toutou 2003-01-03
  • 打赏
  • 举报
回复
声明
FUNCTION long lTest(decimal f_in, ref string s_in, ref decimal f_out, ref long l_out, ref string s_out) LIBRARY "dlltest.DLL"
参数s_out在调用前要分配空间,用space(100)什么地赋值就可以
hjd_cw 2003-01-03
  • 打赏
  • 举报
回复
dll 在PB里不能调用,一般不是PB的原因。
这主要取决于生成DLL时,函数原型的定义是否正确。
VC:
1.要以 int WINAPI MyFunction(char * str,int aaa) ; 的形式定义函数
2.要在*.def文件里显式的导出(exports)该函数
DELPHI:
1.要以 function MyFunction(MyStr :pchar;MyInt :integer):integer;stdcall;
的形式声明函数。
2.要在exports 段,导出该函数名称,如
exports
MyFunction index 1;
luomario 2003-01-03
  • 打赏
  • 举报
回复
我知道VC中的long是8字节,而PB中的long是4字节。不知道这样双方都用long有没有影响?


但是现在我发现这样一个问题:
在VC中定义:
extern "C" _declspec(dllexport) int iTestFunc()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return 8;
}
在PB中声明:
FUNCTION long iTestFunc() LIBRARY "dlltest.DLL"
在PB中调用:
messagebox("", iTestFunc())
这样用没有任何问题。

但是照如下改:
在VC中定义:
extern "C" _declspec(dllexport) int iTestFunc(int iValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return 8;
}
在PB中声明:
FUNCTION long iTestFunc(long iValue) LIBRARY "dlltest.DLL"
在PB中调用:
messagebox("", iTestFunc(3))
结果却是报错:
Error:specified argument type differs from required argument type at runtime in DLL function iTestFunc.(invalid stack pointer on return from function call)
怎么回事???
zhangjun 2002-12-18
  • 打赏
  • 举报
回复
ref有返回值的
zyn01 2002-12-18
  • 打赏
  • 举报
回复
声明函数中的数据类型不匹配,注意对应的pb中的数据类型
这样声明试试:
function long 1test(decimal f_in,ref string s_in,ref decimal f_out,ref long l_out, ref string s_out) library "dlltest.dll"

1,108

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧