///标准接口
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;

解决方案 »

  1.   

    听说D2008可以在record中继承,不知是不是,木有用过,看看有没人给出测试结果。如果可以,转过来应该是这样:type
      IKnown = record
        function Release: Cardinal; stdcall; virtual; abstract;
      end;  IService = record(IKnow) // ???是不是这样写的?
         function Get: Integer; stdcall; virtual; abstract;
      end;
      

  2.   

    哦,我的是delphi6,抱歉我没说清楚delphi6中要怎么转
      

  3.   

    D7以下不支持这种写法,如果要真要转,只能以指针指向的方法来转,
    大概是这样:
    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里面的区别就比较大了。
      

  4.   

    同意楼上,C++里面的struct跟class差不多,可以继承.
    直接翻译成class.type
      IKnown = class(TObject)
        ///接口
        function Release: DWORD; stdcall;
      end;///服务接口 
      IService = class(IKnown)
        ///返回版本号
        function Get(const lpBuffer: Pointer): Integer; stdcall;
      end;
      

  5.   

    啊啊,实在是不行,找了下,都没能出什么结果。哎。。拿到的是一个用C写的DLL和他的头文件。需要在Delphi中调用里面的函数,Delphi的申明怎么写哦
    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
      

  6.   

    type 
      IKnown = interface(IUnknown) 
        ///接口 
        function Release: DWORD; stdcall; 
      end; ///服务接口 
      IService = interface(IKnown) 
        ///返回版本号 
        function Get(const lpBuffer: Pointer): Integer; stdcall; 
      end; 
    难道这样?
      

  7.   

    这个可以这样调用:
    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和那开发定义传到某地,我下载测试看看。
      

  8.   

    写成interface,该怎么去调用dll中的函数?
      

  9.   

    没办法写,上面有人提到用class,但最终调用时可能会出现问题,最有效的方法,重新用c++再作一次封装,或者换工具开发
      

  10.   

    ERRORCODE 有邮箱地址吗?我发你邮件吧。
      

  11.   


    dll也不能做到通用啊??以前一直以为C和Delphi写的dll只要格式标准都可以通用的
      

  12.   

    哎,试着写了个class,编译通过,输入点的函数也获取正常,但获取到第二层的Struct就出错误了。