FIX: Platform SDK Causes MIDL to Throw MIDL2311 Error (243219)
The information in this article applies to:
- Microsoft Platform Software Development Kit (SDK) 1.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q243219 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:
#include <olectl.h> - 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:
#ifndef _OLECTL_H_
#define _OLECTL_H_
#if _MSC_VER > 1000
#pragma once
#endif
#if !defined(__MKTYPLIB__) && !defined(__midl)
// most of the file
#endif
// some #defines
#endif
Change it to:
#ifndef _OLECTL_H_
#define _OLECTL_H_
#if !defined(__MKTYPLIB__) && !defined(__midl)
#if _MSC_VER > 1000
#pragma once
#endif
// most of the file
#endif
// some #defines
#endif
STATUSMicrosoft has confirmed that this is 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.
REFERENCESFor additional information on searching the Knowledge Base, click the article number below
to view the article in the Microsoft Knowledge Base:
242971 HOWTO: Use the Developer Support Microsoft Knowledge Base
Modification Type: | Minor | Last Reviewed: | 7/11/2005 |
---|
Keywords: | kbBug kbfix KB243219 kbAudDeveloper |
---|
|