Microsoft KB Archive/243219

{|
 * width="100%"|

FIX: Platform SDK Causes MIDL to Throw MIDL2311 Error

 * }

Q243219

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK)
 * Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0
 * Microsoft Visual C++, 32-bit Professional Edition, version 6.0
 * Microsoft Visual C++, 32-bit Learning Edition, version 6.0

-

SYMPTOMS
When you use the Microsoft Interface Definition Language (MIDL) with the /mktypelib203 switch to compile an .odl file, MIDL reports the following error:

MIDL2311 : statements outside library block are illegal in mktyplib compatibility mode.

This happens when you use SDK headers that are included in the July 1999 Platform SDK. When the INCLUDE path points to Visual C++ 6.0 headers first, this problem does not occur and the application builds.

CAUSE
This problem may occur if all of the following conditions are met:

  There is a bug in the MIDL code specific to /mktyplib203 processing. The #pragma once in the SDK header files, Olectl.h, is not recognized by MIDL when the /mktyplib203 switch is on.  The Tool wizard defaults to /mktyplib203, which is unnecessary. (Do not use /mktyplib203 unless you are dealing with code dating back to mktyplib version 2.03, which does not compile with a newer MIDL compiler.) A bug exists in the SDK Olectl.h file that does not hide the section #pragma once properly.

RESOLUTION
There are four possible solutions for this problem:

 Install the latest Platform SDK available at: Do not use the /mktyplib203 switch unless you have to deal with legacy code dating back to mktyplib ver.2.03. In the .odl file, put the following inside the library block:  In the SDK Olectl.h file, move the section with #pragma once inside the part of the file invisible to MIDL or mktyplib.

The SDK olectl.h file looks like this:

<pre class="CODESAMP">#ifndef _OLECTL_H_
 * 1) define _OLECTL_H_


 * 1) if _MSC_VER > 1000
 * 2) pragma once
 * 3) endif

// most of the file
 * 1) if !defined(__MKTYPLIB__) && !defined(__midl)
 * 1) endif

// some #defines
 * 1) endif

Change it to: </li></ul>

STATUS
Microsoft has confirmed this to be a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in the January 2000 Platform SDK.

Steps to Reproduce Behavior

 * 1) Install Visual C++ 6.0 Service Pack 3.
 * 2) Install the Platform SDK, July 1999, from MSDN.
 * 3) Start Visual C++.
 * 4) From the File menu, select New.
 * 5) On the Projects tab, select MFC ActiveX ControlWizard. In the Project Name edit box, type the name of the project, for example:
 * 6) Click OK.
 * 7) Click Finish.
 * 8) Finally, from the Build menu, select Build <projectname> to build the project.

The following error message appears in the .odl file:

file.odl(1) : error MIDL2311 : statements outside library block are illegal in mktyplib compatibility mode : [ ]