3

我们有一个 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 "Debug\SampleGenerated.tlb"
4

1 回答 1

0

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

首先将每个接口拆分为单独的 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 文件。

于 2013-10-30T08:23:28.303 回答