c++ - 中间错误 MIDL2379

标签 c++ windows com midl

我们有一个 c++ 库,我们正在为该库自动生成 COM 接口(interface)。所以我自动生成了 IDL 文件,一切正常。但是随着时间的推移,当更多接口(interface)被添加到 COM 时,我们开始收到错误

1> Total Format String size = 69336
1> midl : error MIDL2379: the compiler reached a limit for a format string representation. See documentation for advice.

我在 VS2008 和 VS2010 中都遇到了这个错误。

谁能帮我解决这个问题。我在互联网上搜索,找不到合适的解决方案。 Microsoft Connect 中报告了一个错误,但它的状态是关闭的。他们建议的一种解决方法是拆分 IDL 文件,这在我的情况下是不可能的,因为接口(interface)相互依赖。

我已经上传了一个示例 IDL 文件 SampleGenerated.idl

这里是 midl 的命令行。

/W1 /nologo /char signed /env win32 /h "SampleGenerated_h.h" /tlb "Debug\SampleGenerated.tlb"

最佳答案

这就是我最终设法做到的...

首先将各个接口(interface)拆分成单独的IDL文件

Interface1.idl

Interface Interface2; // forward declaration

#ifndef __Interface1_IDL_FILE_
#define __Interface1_IDL_FILE_
import "AllIDLInterface.idl";
[
    object,
    uuid(66006A2F-B777-4e2f-A0CA-D5BE00000015),
    dual,
    nonextensible,
    pointer_default(unique)
]
interface Interface1 : IUnknown{
HRESULT getInterface2([out, retval]Interface2** outVal )
};
#endif

Interface2.idl

Interface Interface1;// forward delcarations

#ifndef __Interface2_IDL_FILE_
#define __Interface2_IDL_FILE_
import "AllIDLInterface.idl";

[
    object,
    uuid(66006A2F-B777-4e2f-A0CA-D5BE00000015),
    dual,
    nonextensible,
    pointer_default(unique)
]
interface Interface2 : IUnknown
{
HRESULT getInterface1([out, retval]Interface1** outVal )
};
#endif

创建另一个 IDL 文件 AllInterface.idl 包含所有接口(interface)文件的导入

import Interface1.idl
import Interface2.idl

现在 ma​​in.idl 我们将为其创建 TLB 文件

import AllInterface.idl;

这里唯一的缺点是,如果我们想生成接口(interface)的C++/C头文件,我们必须单独编译每个IDL文件。

关于c++ - 中间错误 MIDL2379,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19626569/

相关文章:

c++ - *** 检测到 glibc *** free() : invalid pointer:

.net - FileLogTraceListener 抛出 System.IO.Exceptions

c++ - 将视频文件加载到 C++ 中的缓冲区中

c++ - Direct3D COM 接口(interface)的发布顺序重要吗?

c++ - COM 使用 CoMarshalInterThreadInterfaceInStream 来编码接口(interface)

c++ - 使用最佳编译器标志和配置从 cmake 运行 Halide 生成器

c++ - MSDN HMAC-SHA1 示例不工作

c++ - 用于 mingw 的 msi.h

c# - 如何将 COM 互操作代理生成到 C# 源代码中?

c++ - 'Figure::Figure()' 的原型(prototype)与类 'Figure' 中的任何一个都不匹配