///标准接口
struct IKnown
{
///接口
virtual unsigned long __stdcall Release()=0;
};///服务接口
struct IService : IKnown
{
///返回版本号
virtual int __stdcall Get(const void * lpBuffer) = 0;
};
这个转成delphi应该怎么转?我听朋友说struct可以转成delphi的record,但C中struct做了继承,delphi中该怎么处理 TStruct = record
function release(): longword;
end;
struct IKnown
{
///接口
virtual unsigned long __stdcall Release()=0;
};///服务接口
struct IService : IKnown
{
///返回版本号
virtual int __stdcall Get(const void * lpBuffer) = 0;
};
这个转成delphi应该怎么转?我听朋友说struct可以转成delphi的record,但C中struct做了继承,delphi中该怎么处理 TStruct = record
function release(): longword;
end;
IKnown = record
function Release: Cardinal; stdcall; virtual; abstract;
end; IService = record(IKnow) // ???是不是这样写的?
function Get: Integer; stdcall; virtual; abstract;
end;
大概是这样:
type
IKnown = record
Release: function: Cardinal; stdcall;
end; IService = record
//无法继承,使用下面中一个来处理
//Release: function: Cardinal; stdcall;
//Known_Release: IKnown;
Get: function: Integer; stdcall;
end;很勉强,建议直接转成class的形式来写。
C++里面struct和class的区别不大,所以他们在写struct,其实跟class基本差不多(具体区查查,好像就几个点不同)
而D里面的区别就比较大了。
直接翻译成class.type
IKnown = class(TObject)
///接口
function Release: DWORD; stdcall;
end;///服务接口
IService = class(IKnown)
///返回版本号
function Get(const lpBuffer: Pointer): Integer; stdcall;
end;
struct IKnown
{
virtual unsigned long __stdcall _QueryInterface(const int & iid, IKnown **ppv )=0;
virtual unsigned long __stdcall _AddRef()=0;
virtual unsigned long __stdcall _Release()=0;
};struct IWorkService : IKnown
{
virtual IWorker * __stdcall GetWorker(int iVersion) = 0;
virtual void __stdcall FreeWorker(IWorker * lpWorker) = 0;
};struct IWorker
{
virtual void __stdcall SetBuffer(void * pBuf,int iBufSize)=0;
virtual int __stdcall getVersion(void) = 0;
};
#ifdef __cplusplus
extern "C"
#endif
IKnown * __stdcall getWorkServiceInstance();#ifdef __cplusplus
}
#endif
IKnown = interface(IUnknown)
///接口
function Release: DWORD; stdcall;
end; ///服务接口
IService = interface(IKnown)
///返回版本号
function Get(const lpBuffer: Pointer): Integer; stdcall;
end;
难道这样?
type
PKnown = ^IKnown;
IKnown = record
_QueryInterface: function(var iid: Integer; var ppv: PKnown): Cardinal; stdcall;
_AddRef: function: Cardinal; stdcall;
_Release: function: Cardinal; stdcall;
end; IWorkService = record
known: IKnown;
GetWorker:....
end;
...function getWorkServiceInstance(): PKnown; stdcall;你这样测试下。不知行不行。不然将那DLL和那开发定义传到某地,我下载测试看看。
dll也不能做到通用啊??以前一直以为C和Delphi写的dll只要格式标准都可以通用的