封装spcomm的问题

cloud976 2011-02-20 03:26:27
想把spcomm封装到一个dll里面,在里面做一些基本的数据检查,接收数据的时候直接取得有用数据。可是不知道需要怎样封装onReceiveData才能在调用的时候监听到这个事件。
...全文
190 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
无条件为你 2011-02-24
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 cloud976 的回复:]
现在问题已经解决,不过还有个问题是,dll在Delphi里面调用正常,在VB里面就出错。

[/Quote]

解决了就应该分享下解决方案。
cloud976 2011-02-23
  • 打赏
  • 举报
回复
现在问题已经解决,不过还有个问题是,dll在Delphi里面调用正常,在VB里面就出错。

已经看了stdcall和string的问题,但是还是调用的时候直接把VB弹死
cloud976 2011-02-22
  • 打赏
  • 举报
回复
[code=Delphi(Pascal])
library lib_spcomm;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,Spcomm , Windows,
Classes;
type
TCommOper = procedure (buff:Array of Byte);stdcall ;
var
comm : TComm;
comm_oper : TCommOper;
procedure Comm_recv(Sender:TObject; buffer:Pointer; length:Word);
var buf: array of Byte;
begin
SetLength(buf, length);
CopyMemory(@buf[0], buffer, length);
comm_oper(buf);
end;
procedure Comm_init(name:string; baudrate:SmallInt; c_oper: TCommOper); stdcall ;
begin
comm.CommName := name;
comm.BaudRate := baudrate;
comm_oper := @c_oper;
try
comm.StartComm;
except
end;
comm.Outx_XonXoffFlow := False;
comm.Inx_XonXoffFlow := False;
comm.OnReceiveData := Comm_recv;
end;
{$R *.res}

begin
end.

[/code]

编译的时候在comm.OnReceiveData这行报method pointer and regular procedure错。应该怎么解决
cloud976 2011-02-20
  • 打赏
  • 举报
回复
还是不甚明白,我的调用是在VB里面调用,在触发onReceivedata事都会触发VB里面的另一个函数。
bdmh 2011-02-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cloud976 的回复:]
[code=Delphi(Pasca]
type
TonReceiveData = TComm.onReceiveData;
var
procedure Recv(Foo: TonReceiveData);stdcall
begin

end;
[/code]
这样子?
[/Quote]
你感觉不错,给你个参考
http://hi.baidu.com/plovemxz/blog/item/d590f71d5c36019987d6b6f4.html
cloud976 2011-02-20
  • 打赏
  • 举报
回复
[code=Delphi(Pascal]
type
TonReceiveData = TComm.onReceiveData;
var
procedure Recv(Foo: TonReceiveData);stdcall
begin

end;
[/code]

这样子?
bdmh 2011-02-20
  • 打赏
  • 举报
回复
dll接口中传入onReceiveData参数,即回调函数,关于回调函数,请自己查阅资料

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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