我们有一个 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
现在 main.idl 我们将为其创建 TLB 文件
import AllInterface.idl;
这里唯一的缺点是,如果我们想生成接口(interface)的C++/C头文件,我们必须单独编译每个IDL文件。
关于c++ - 中间错误 MIDL2379,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19626569/