FIX: Platform SDK Prevents MFC Projects from Compiling
ID: Q243503
|
The information in this article applies to:
-
The Microsoft Foundation Classes (MFC), used with:
-
Microsoft Visual C++, 32-bit Editions, version 6.0
SYMPTOMS
When compiling a MFC ActiveX project with Microsoft Visual C++ 6.0 and the Platform SDK installed, you may get compiler errors when building the project. You may get a "C2146" error in the project C++ source file for the CWinApp derived class not being defined.
This did not happen before installing the Platform SDK.
CAUSE
This is due to the project header file being overwritten by the MIDL compiler generated header file. This only happens when the /mktyplib203 switch is not specified when compiling an .odl file and the .odl file has the following line of code outside of the library block.
#include <olectl.h>
RESOLUTION
At this time, it is recommended to not select the MkTypLib compatible option when building MFC ActiveX components. This option can be found from Project menu Settings menu and then select MIDL tab.
Removing the MkTypLib compatible option may overwrite the project header file that results in the compiler error mentioned in the "Symptoms" section of this article. Instead, move any #include statements in the .odl file inside of the library block. For example:
[ uuid(9D830476-7DAB-11D3-9D15-00C04F542A77), version(1.0),
helpfile("testodl5.hlp"),
helpstring("testodl5 ActiveX Control module"),
control ]
library TESTODL5Lib
{
#include <olectl.h> //move this to here to prevent any MIDL 2311 errors
#include <idispids.h>
importlib(STDOLE_TLB);
importlib(STDTYPE_TLB);
//...rest of code omitted
}
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article.
This problem was corrected in the Microsoft Platform SDK January 2000 Edition.
MORE INFORMATION
Steps to Reproduce Behavior
- Install Platform SDK for Windows 2000 RC2.
- Select Typical Install when prompted, and then select Enable Visual VC++ Integration.
- Run Visual C++ 6.0.
- From the Tools menu select Options and then select Directories tab.
- Move the Platform SDK include directories to the top of the list.
- Move the Platform SDK LIB directories to the top of the list.
- Create a new MFC ActiveX control. Do this by from the File/New menu select the Projects tab and then select MFC ActiveX Control Wizard. Name the project "PlatOCX".
- Open the PlatOCX.odl file by selecting Open from the File menu.
- Build the PlatOCX.odl file by selecting the Build/Compile PlatOCX.odl menu item.
- You should get a MIDL error 2311. This is OK. You can disable this by selecting the Project menu, Settings menu and then selecting the MIDL tab, and deselecting the MkTypLib compatible checkbox.
- Build the PlatOCX.odl file again.
You should notice that the PlatOCX.odl file compiles cleanly now. However, you should also notice that the AppWizard generated PlatOCX.h header file was overwritten with the MIDL generated header file.
REFERENCES
Additional query words:
C2146 MIDL 2311 ODL Data loss overwrite header file
Keywords : kbActiveX kbCOMt kbMFC kbSDKPlatform kbVC600bug kbDSupport kbfix kbGrpMFCATL kbIDL kbMIDL
Version : winnt:6.0
Platform : winnt
Issue type : kbbug