pb9 调用 api 问题

poptang4 2011-03-24 06:20:35
在 Local External Functions 里面定义了如下
Function ulong GetComputerName(ref String ls_Buffer, int nSize) Library "kernel32"

但在一个button 里面调用确出错:
string ls_computer_name
ls_computer_name = space(100)

GetComputerName(ls_computer_name,100)
MessageBox("",ls_computer_name)

显示:Error calling external function getcomputername at line 23 in clicked event of object cb_3 of w_main
怎么调用啊?
...全文
237 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pcwe2002 2011-03-25
  • 打赏
  • 举报
回复
要看函数的说明最好安装一个msdn
yyoinge 2011-03-24
  • 打赏
  • 举报
回复
poptang4 2011-03-24
  • 打赏
  • 举报
回复
但是,我如果需要调用某个API时候,我怎么能知道这个API的参数,到底是要ref,还是不需要ref的呢?
这个API 我是使用 FoxAPI里面的定义拿来的,原型是这样:
Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

里面的nSize并没有定义需要地址的引用啊。难道要我猜吗?
poptang4 2011-03-24
  • 打赏
  • 举报
回复
thanks!!!
zhgwbzhd 2011-03-24
  • 打赏
  • 举报
回复
声明时:
Function ulong GetComputerNameA(ref String ls_Buffer,ref ulong nSize) Library "Kernel32"

代码:
string ls_computer_name
ulong i

ls_computer_name = space(100)

i = 100

GetComputerNameA(ls_computer_name,i)
MessageBox("",ls_computer_name)

已经在pb9下测试通过。
yyoinge 2011-03-24
  • 打赏
  • 举报
回复
ref 不要去掉
yyoinge 2011-03-24
  • 打赏
  • 举报
回复
string ls_computer_name
long ll_size = 100
ls_computer_name = space(ll_size)
GetComputerName(ls_computer_name,ll_size)
MessageBox("",ls_computer_name)

poptang4 2011-03-24
  • 打赏
  • 举报
回复
出现:
---------- Compiler: Errors
demo.pbl(w_main).cb_3.clicked.23: Error C0082: Reference argument must be a non-constant and non-readonly variable reference.
---------- Finished Errors

应该是ref ulong nSize 去掉 ref吧,但是去掉后,又提示头一个错误了。
yyoinge 2011-03-24
  • 打赏
  • 举报
回复
这样声明
FUNCTION ulong GetComputerName(ref string lpBuffer,ref ulong nSize) LIBRARY "kernel32.dll" ALIAS FOR "GetComputerNameA"

680

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder API 调用
社区管理员
  • API 调用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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