5

In Visual Studio, when you compile foo.idl, MIDL generates the proxy information in foo_p.c.

Unfortunately, for Win32 and x64 files, it uses the same filename. For Win32, the file starts with:

#if !defined(_M_IA64) && !defined(_M_AMD64)

For x64, the file starts with:

#if defined(_M_AMD64)

When you build for Win32 and then immediately build for x64, it doesn't replace the foo_p.c file, meaning that the project fails to link.

I tried having a pre-build event that deletes the foo_p.c file if it's for the wrong architecture, but VS doesn't even bother to run that step.

How should I get it so that I can build one configuration and then the other?

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380

2 Answers2

4

You could modify the compiler settings for your IDL file to specify a different file name for the output proxy file according to the target platform. (Select Properties on the IDL file, then Configuration Properties / MIDL / Output).

  • For Win32 builds, use foo_p_w32.c
  • For x64 builds, use foo_p_x64.c

Then, in your Win32 project settings, exclude the file foo_p_x64.c and vice versa for the x64 project.

You need to do the same for the _i.c file, otherwise Visual Studio doesn't seem to rebuild the IDL at all.

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
ChrisN
  • 16,635
  • 9
  • 57
  • 81
  • This sucks, but it probably is the only solution since dual stub generation in Visual Studio seems to be broken (see http://connect.microsoft.com/VisualStudio/feedback/details/648537/midl-v7-00-0555-do-not-create-dual-stubs-by-default). Thanks for posting your answer! – Helge Klein May 02 '12 at 21:49
0

Here are the configuration changes we use to allow automated builds to work cleanly

Change

<Tool
Name="VCMIDLTool"
TypeLibraryName="$(ProjectName).tlb"
OutputDirectory="$(SolutionDir)$(PlatformName)"
HeaderFileName="$(ProjectName)_h.h"
DLLDataFileName="$(ProjectName)_dlldata.c"
/>

To

<Tool
    Name="VCMIDLTool"
    TypeLibraryName="$(InputName).tlb"
    OutputDirectory="$(SolutionDir)$(PlatformName)"
    HeaderFileName="$(InputName)_i.h"
    DLLDataFileName="$(InputName)_dlldata.c"
    InterfaceIdentifierFileName="$(InputName)_i.c"
    ProxyFileName="$(InputName)_p.c"
/>

and add $(SolutionDir)$(PlatformName) to your C++ Additional Include Directories

e.g.

<Tool Name="VCCLCompilerTool" ...
AdditionalIncludeDirectories="...;&quot;$(SolutionDir)$(PlatformName);&quot;"
dexblack
  • 551
  • 4
  • 3