3

We have a c++ library and we are auto generating COM interface for that library. so I auto generated the IDL file and everything was working fine. But over time when more interface were added to COM, We started getting the error

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

I am getting this error in both VS2008 and VS2010.

Can any one please help me how to fix this problem. I searched all over internet and couldn't find a proper solution. There is one bug reported in Microsoft Connect, but it's status is closed. One work around they suggest is to split the IDL file, which is not possible in my case, cause the interfaces have dependency with one other.

I have uploaded a sample IDL file SampleGenerated.idl

here is the command line to midl.

/W1 /nologo /char signed /env win32 /h "SampleGenerated_h.h" /tlb "Debug\SampleGenerated.tlb"
Raptor
  • 53,206
  • 45
  • 230
  • 366
Naveen
  • 31
  • 3
  • Ouch. "Closed as external" means "it's not a VS problem so we don't care that much and will close it" and so I guess the problem will not be fixed in less than 20 years and you'll have to workaround the problem. One of the workarounds listed there are to refactor the IDL by distributing interfaces over multiple files. Have you tried that workaround? – sharptooth Oct 28 '13 at 06:21
  • Hi @sharptooth , I cannot split the interface to multiple files because my interface are depended on each other. For eg Interface1 might be having a method getIntergface2() which returns Interface2*. There for both Interface1 and Interface2 needed to be in the same IDL file. – Naveen Oct 28 '13 at 07:48
  • Well, are they all dependent this much? Can you separate at least some of them? – sharptooth Oct 28 '13 at 08:27
  • Not actually.. :(. The interfaces are organized in a tree like structure. We have one root interface, from which we get few child interface and from those child interfaces again we can get more child interfaces and so on.. The only option to split will be to change the methods which returns interface pointers to IUnknown*. But doing so will reduce the clarity of interfaces and will be difficult for the client application to use it. – Naveen Oct 28 '13 at 08:51
  • 1
    Well, what happens if you just move those interfaces into separate files and import them to the root interface file? – sharptooth Oct 28 '13 at 09:17
  • I will try that. It will take some time.. I will let you know the result after that.. Thanks.. – Naveen Oct 28 '13 at 10:03
  • Well that worked!! I actually was in the assumption that I might need to compile each idl file separately. But making all my interface as IDL file and importing them in a master IDL file worked (plus I forward declared all the interface file in the beginning). Thanks and lot – Naveen Oct 28 '13 at 11:46
  • Glad to hear it was resolved this easy. – sharptooth Oct 28 '13 at 12:03
  • Could you please add the answer detailing how you solved the problem? – sharptooth Oct 28 '13 at 12:44

1 Answers1

0

This is how I managed to do it finally...

First split each interface to separate IDL file

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

Create another IDL file AllInterface.idl containing import of all interface file

import Interface1.idl
import Interface2.idl

Now the main.idl for which we will be creating TLB files

import AllInterface.idl;

The only draw back here is, we have to compile each IDL file separately, if we want to generated the C++/C header file of interfaces.

Naveen
  • 31
  • 3