高分 请救 !请救 ! delphi 里的函数getmem 在VB6里怎么实现

hbxsq 2018-08-03 11:58:40

RecodeBuf:PChar;
GetMem(RecodeBuf,1300);

用VB6怎样实现
...全文
183 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hbxsq 2018-08-04
  • 打赏
  • 举报
回复
是用VB6来调用DLL,仍然不行

Public Declare Function ReadLSList_Caidan Lib "icxf.dll" Alias "_ReadLSList_Caidan@16" (ByVal macno As LONG, ByVal flag As String, ByRef listcount As Long, ByVal lsSJ As String) As long

调用函数
Private Sub Command21_Click()
Dim intret As Long
Dim flag As String
Dim listcount As Long
Dim recordbuf As String
strlstmp = String$(1300, vbNullChar)
flag = "F"
intret = ReadLSList_Caidan(2, flag, listcount, recordbuf)
Text1 = recordbuf ’读出为空?
End Sub

recordbuf 参数读出来为空的
hbxsq 2018-08-04
  • 打赏
  • 举报
回复
看不到C++函数原型,只能参考DELPHI范例代码,
hbxsq 2018-08-04
  • 打赏
  • 举报
回复
问题 已解决 非常谢谢 舉杯邀明月! 将 flag 参数,声明为integer ,传入asc码70 问题解决了!
舉杯邀明月 2018-08-04
  • 打赏
  • 举报
回复
细想了一下,你的第2个参数应该错误!

API声明,把第2个参数类型改为 byval flag as byte 或 as integer
调用时,传递 asc("F"),或者直接写相应的ASCII码值。
舉杯邀明月 2018-08-03
  • 打赏
  • 举报
回复
“分”再高,也没什么意义了。



不知道你的“函数原型”(C++格式的函数声明)是什么样的。

不过,最大的问题: 你的VB代码中,recordbuf不能那样定义,只能定义成Dim recordbuf As String
    然后,调用API前给它分配足够长度的数据空间,再作为参数传递。
  比如: recordbuf = String$(1300, vbNullChar)
  或者: recordbuf = Space$(1300)
  然后再去调用 ReadLSList_Caidan ( )

threenewbee 2018-08-03
  • 打赏
  • 举报
回复
你是vb6还是vb.net,vb6的话,应该用Long,而不是Integer,因为考虑代码兼容(向前兼容VB1.0~VB4.0),VB的Integer是16bit的,实际上相当于其它语言的short
hbxsq 2018-08-03
  • 打赏
  • 举报
回复
大神,给看是哪错了,解决问题,再送高分
hbxsq 2018-08-03
  • 打赏
  • 举报
回复
上边 DELPHI 读参数 recordbuf 有值 ,下面用VB读出参数为空。原因未知


VB声明及调用方法
Public Declare Function ReadLSList_Caidan Lib "icxf.dll" Alias "_ReadLSList_Caidan@16" (ByVal macno As Integer, ByVal flag As String, ByRef listcount As Long, ByVal lsSJ As String) As Integer

调用函数
Private Sub Command21_Click()
Dim intret As Long
Dim flag As String
Dim listcount As Long
Dim recordbuf As String * 1300

flag = "F"
intret = ReadLSList_Caidan(2, flag, listcount, recordbuf) 'listcount本次读取的记录数
Text1 = recordbuf ’读出为空????????
End Sub

strlstmp参数读出来为空的
hbxsq 2018-08-03
  • 打赏
  • 举报
回复
//手动下载菜单流水函数声明 DLL
function ReadLSList_Caidan(MacNO: Byte; Flag:Char ;var listcount:integer;ls: PChar): integer; stdcall; far; external 'icxf.dll Name '_ReadLSList_Caidan@16'



//调用函数按钮过程
procedure TForm1.Button1Click(Sender: TObject);
VAR

TXTFileName,TemStr,TemStr1,ReadBuf:string;
MacNo,RTurn,ConsumeCount,ConsumeMoney,RecodeList,addflag,listcount,y,hcount:Integer;
flag:Char;
RecodeBuf:PChar;
begin
GetMem(RecodeBuf,1300);
RecodeList:=0;

flag:='F';
RTurn:=ReadLSList_Caidan(2,flag,listcount,RecodeBuf);
MEMO1.Lines.Add (RecodeBuf);//文本框内显示返回的参数值
freemem(recodebuf);
end;
threenewbee 2018-08-03
  • 打赏
  • 举报
回复
vb没有指针,不能动态分配内存

7,763

社区成员

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

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