使用C ++ Builder从COM对象读取GUID属性

时间:2014-04-25 22:43:04

标签: com c++builder

我正在使用第三方COM对象。非常好,但我一直在从对象中读取GUID属性。

自动生成的组件包装器/标头的相关部分如下所示:

// *********************************************************************//
// DispIntf:  IFoo
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {5DE5DAAF-5419-4B2B-9771-58EAEE780799}
// *********************************************************************//
template<class T>
class IFooDispT : public TAutoDriver<IFoo>
{
  ...
BSTR    __fastcall get_FileName(void);
HRESULT __fastcall get_ProjectGUID(/*AUTO_PARAM_ERROR(System::TGUID* Value)*/ VARIANT*  Value);
HRESULT __fastcall get_ProjectName(BSTR* Value/*[out,retval]*/);

__property   BSTR  FileName = {read = get_FileName};
__property   BSTR  ProjectName = {read = get_ProjectName};

请注意ProjectGUID属性如何标记为AUTO_PARAM_ERROR,并且不会显示在属性列表中。

我尝试通过get_ProjectGUID()直接阅读,但它始终返回HRESULT = 0x80070057 (E_INVALID_ARGS)

OleView的dispinterface的IDL如下所示: -

[
  uuid(5DE5DAAF-5419-4B2B-9771-58EAEE780799),
  version(1.0),
  helpstring("Dispatch interface for xpCOMFoo Object"),
  dual
]
dispinterface IFoo {
    properties:
    methods:
 <...snipped...>
        [id(0x000000cf), propget]
        BSTR FileName();
        [id(0x000000d0), propget]
        GUID ProjectGUID();
        [id(0x000000d1), propget]
        BSTR ProjectName();
};

我已经从Delphi中测试了相同的对象(虽然没有使用上面显示的后期绑定),但我很高兴COM对象本身没有错。

1 个答案:

答案 0 :(得分:0)

尝试这样称呼:

TAutoDriver<IFoo> foo;

// ...

GUID guid;
memset(&guid, 0, sizeof(guid));
// use -> to access the raw dual interface
HRESULT hr = foo->get_ProjectGUID(&guid);