VC中IDispatch派生接口方法的原型为:
HRESULT Start(BSTR p_Unit, BSTR p_Method, BSTR p_Parameter);
返回值为HRESULT类型。可是用VC生成的*.tlb文件,转变为Delphi的*_TLB.pas文件时,函数原型变为:
procedure Start(const p_Unit: WideString; const p_Method: WideString; 
                const p_Parameter: WideString); safecall;
没有返回值。我该怎么得到VC中函数的返回值?谢!

解决方案 »

  1.   

    这是 DELPHI里面的
    Calling conventions 
    Directive Parameter order Clean-up Passes parameters in registers?
    register Left-to-right Routine Yes
    pascal Left-to-right Routine No
    cdecl Right-to-left Caller No
    stdcall Right-to-left Routine No
    safecall Right-to-left Routine NoVC的safecall 好像没见过。procedure Start(const p_Unit: WideString; const p_Method: WideString; 
                    const p_Parameter: WideString); safecall;
    还都用const??没搞错 那这个函数有什么意义起码要用个var引用吧。。
      

  2.   

    procedure Start(const p_Unit: WideString; const p_Method: WideString; 
                    const p_Parameter: WideString); safecall;
    上面这个函数是delphi自动生成的!VC当然没有safecall,可是VC的IDispatch接口方法,转变为delphi的方法时,就变为safecall的了。
      

  3.   

    typedef LONG          HRESULT; 
    HRESULT -> LONGIN COM:
    HRESULT 
    An opaque result handle defined to be zero for a successful return from a function and nonzero if error or status information is returned. To convert an HRESULT into the more detailed SCODE, applications call GetScode(). See also SCODE.
      

  4.   

    没看明白?!我不是想知道HRESULT代表什么!我只想知道,用VC写的接口函数,经过Delphi的自动转换工具的转换,它的返回值到哪里去了?怎么得到它?谢谢!
      

  5.   

    在VC中IDispatch派生接口方法中添加一个返回参数:
    HRESULT Start(BSTR p_Unit, BSTR p_Method, BSTR p_Parameter,long ReturnValue);
    把返回的S_OK或者S_FALSE赋给ReturnValue,然后在转化到Delphi中或VB中就会是一个函数而不是过程。
    在内部处理上HRESULT就是一个LONG型的长整数
      

  6.   

    typedef OLECHAR *BSTR;BSTR是 字符串指针呀。。
    你的转换工具错误了吧 DELPHI中有LRESULT类型的直接用就是 其实也就是一个LONG<在DELPHI中是一个LongInt>
      

  7.   

    从HRESULT 转成SAFECALLHRESULT的值被处理成异常传出来的。。可以省掉你检查那一步。