我创建了一个实现某些接口的 COM 类。我想向这个接口添加一个方法。该方法的参数是指向某个外部 olb 文件中定义的接口的指针。在我的项目中,这个 olb 文件在没有no_namespace
指令的情况下导入。因此,方法参数中的接口名称必须在 h\cpp 文件中进行限定。但是 MIDL 不识别命名空间并在方法中生成带有不合格接口的头文件。所以,错误 C2061。一个小样本:
//stdafx.h
#import "somelib.olb" named_guids no_function_mapping
在 somelib.olb 中定义了 interface 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'
如何解决这个问题呢?提前致谢。