midl error MIDL2379

midl error MIDL2379

本文关键字:MIDL2379 error midl      更新时间:2023-10-16

我们有一个 c++ 库,我们正在为该库自动生成 COM 接口。 所以我自动生成了 IDL 文件,一切正常。但是随着时间的推移,当更多接口添加到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 文件,这在我的情况下是不可能的,因为接口彼此依赖。

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

这是 midl 的命令行。

/W1 /nologo /char signed /env win32 /h "SampleGenerated_h.h" /tlb "DebugSampleGenerated.tlb"

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

首先将每个接口拆分为单独的 IDL 文件

接口1.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

接口2.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 包含导入的所有接口文件

import Interface1.idl
import Interface2.idl

现在我们将为其创建 TLB 文件的 main.idl

import AllInterface.idl;

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

相关文章: