在delphi中怎样 type 这个回调函数? ( 积分: 50 )

  • 主题发起人 主题发起人 月冷无痕
  • 开始时间 开始时间

月冷无痕

Unregistered / Unconfirmed
GUEST, unregistred user!
DLL中 C++ builder 的函数原型
typedef void (__fastcall *TUsbDeviceChangeEvent)(char* strDevLocalName,int nStatus,void* object)

typedef void (WINAPI *pSetUsbEvent)(TUsbDeviceChangeEvent UsbEvent);

在delphi中怎样 type 这个回调函数,用什么关键字修饰.void* object 在delphi中怎么对应, 先谢过各位大侠了!
 
fastcall就是delphi的register调用规则
 
void * 就是Pointer,无类型指针,不过看参数好象指向的是一个对象? 不同编译器用DLL传对象可不行
 
//不过就是定义两个函数指针类型而已
{
typedef void (__fastcall *TUsbDeviceChangeEvent)(char* strDevLocalName,int nStatus,void* object)

typedef void (WINAPI *pSetUsbEvent)(TUsbDeviceChangeEvent UsbEvent);
}

Type
TUsbDeviceChangeEvent = procedure(strDevLocalName: PCHAR
nStatus:Integer
__Object : Pointer)
register;

Type
pSetUsbEvent = procedure(UsbEvent : TUsbDeviceChangeEvent)
stdcall;
 
Type
TUsbDeviceChangeEvent = procedure( strDevLocalName: PCHAR
nStatus:Integer
__Object: Pointer) of object
register;

TSetUsbEvent = procedure(UsbEvent : TUsbDeviceChangeEvent)
stdcall;

TEventObject = class
public
class procedure Callback( strDevLocalName: PCHAR;
nStatus:Integer;__Object:Pointer);
end;

class procedure TEventObject.Callback( strDevLocalName: PCHAR
nStatus:Integer
__Object: Pointer);
begin
//
end;

调用时:SetUsbEvent(EventObject.Callback) 就出错!
 
老兄,of object是Delphi的定义,和C++是不兼容的。另外class procedure也不正确。你唯一声明的方式是
procedure MyCallBackFunc( strDevLocalName: PCHAR
nStatus:Integer
__Object: Pointer)
register;
 
Type
TProcedure = Procedure;
TUsbDeviceChangeEvent = procedure(strDevLocalName: PCHAR
nStatus:Integer
__Object : TProcedure)
register;Cdecl;

Type
pSetUsbEvent = procedure(UsbEvent : TUsbDeviceChangeEvent)
Cdecl;
 
to wql
如果这样回调函数怎么定义和调用啊,? 大侠帮帮忙吧!
 
哪里要加 of object ???
 
感谢各位大侠的帮助!问题已经解决了,爽啊!
 
后退
顶部