导入类型库的 IDL 中的名称不合格

发布于 2024-09-07 09:52:07 字数 1102 浏览 0 评论 0原文

我创建了一个实现某些接口的 COM 类。我想向这个接口添加一个方法。该方法的参数是指向某个外部 olb 文件中定义的接口的指针。在我的项目中,这个 olb 文件是在没有 no_namespace 指令的情况下导入的。因此,方法参数中的接口名称必须在 h\cpp 文件中进行限定。但 MIDL 无法识别名称空间,并会在方法中生成具有不合格接口的头文件。因此,错误 C2061。一个小例子:

//stdafx.h
#import "somelib.olb" named_guids no_function_mapping

在 somelib.olb 中定义了接口 Foo。它在我的项目中的限定名称是 someLib::Foo

//myproject.idl
...
[
  object,
  uuid(...),
  ...
]
library MyProjectLib
{
  importlib(somelib.olb);
  ...
  [
     object,
     uuid(...),
     helpstring(...),
     pointer_default(unique)
  ]
  interface IMyInterface : IUnknown{
     [propputref, helpstring("...")] HRESULT Bar ([in] IFoo* Parent);
  };

MIDL 生成头文件 MyProject.h

//MyProject.h
...
IMyInterface : public IUnknown
{
public:
    virtual /* [helpstring][propputref] */ HRESULT STDMETHODCALLTYPE putref_Bar( 
        /* [in] */ /* external definition not present */ IFoo *Parent) = 0;
};
...

和错误消息

error C2061: syntax error : identifier 'IFoo'

如何解决这个问题?提前致谢。

I've created a COM-class that implements some interface. I want to add a method to this interface. The parameter of this method is a pointer to the interface defined in some external olb-file. In my project this olb-file imported without no_namespace directive. So, the interface name in the parameter of the method must be qualified in h\cpp files. But MIDL doesn't recognize namespaces and generates header file with unqualified interface in the method. So, error C2061. A little sample:

//stdafx.h
#import "somelib.olb" named_guids no_function_mapping

In somelib.olb defined interface Foo. It's qualified name in my project is someLib::Foo

//myproject.idl
...
[
  object,
  uuid(...),
  ...
]
library MyProjectLib
{
  importlib(somelib.olb);
  ...
  [
     object,
     uuid(...),
     helpstring(...),
     pointer_default(unique)
  ]
  interface IMyInterface : IUnknown{
     [propputref, helpstring("...")] HRESULT Bar ([in] IFoo* Parent);
  };

MIDL generates header file MyProject.h

//MyProject.h
...
IMyInterface : public IUnknown
{
public:
    virtual /* [helpstring][propputref] */ HRESULT STDMETHODCALLTYPE putref_Bar( 
        /* [in] */ /* external definition not present */ IFoo *Parent) = 0;
};
...

And error message

error C2061: syntax error : identifier 'IFoo'

How to solve this problem? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文