Microsoft KB Archive/224610

= BUG: You receive C2146 and C2501 compiler errors in the .tlh file or the .tli file when you use the #import statement to create smart pointers for an ActiveX server =

Article ID: 224610

Article Last Modified on 9/8/2005

-

APPLIES TO


 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q224610



SYMPTOMS
When using #import to create smart pointers for an ActiveX server, you may see C2146 and C2501 compiler errors in either of the .tlh or .tli files. This will happen if the type library used IFontDisp and IPictureDisp interfaces.

circ3.tlh(54) : error C2146: syntax error : missing ';' before identifier 'Font'

circ3.tlh(54) : error C2501: 'FontPtr' : missing storage-class or type specifiers



CAUSE
IFontDisp and IPictureDisp are just typedefs for the interfaces Font and Picture respectively. The header file Comdef.h incorrectly declares smart pointer classes for the synonyms IFontDisp and IPictureDisp rather than the actual interface types Font and Picture. This is what results in the compilation error.



RESOLUTION
In order to get around this error, #import the typelib Stdole2.tlb prior to importing the ActiveX servers typelib and make sure that they exist in the same namespace. For example, if you were using the CIRC3 MFC ActiveX control, employ the following code as the workaround:

"OLE_XPOS_PIXELS", "OLE_YPOS_PIXELS", "OLE_XSIZE_PIXELS", "OLE_YSIZE_PIXELS", "OLE_XPOS_HIMETRIC", \ "OLE_YPOS_HIMETRIC", "OLE_XSIZE_HIMETRIC", "OLE_YSIZE_HIMETRIC", "OLE_XPOS_CONTAINER", \ "OLE_YPOS_CONTAINER", "OLE_XSIZE_CONTAINER", "OLE_YSIZE_CONTAINER", "OLE_HANDLE", "OLE_OPTEXCLUSIVE", \ "OLE_CANCELBOOL", "OLE_ENABLEDEFAULTBOOL", "FONTSIZE", "OLE_COLOR") using namespace New;
 * 1) import "c:\winnt\system32\stdole2.tlb" rename_namespace("New") exclude("GUID", "DISPPARAMS", "EXCEPINFO", \
 * 1) import "debug\circ3.tlb" rename_namespace("New")



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
One case where this issue showed up involved using #import to create smart pointers for the Circ3 MFC ActiveX control sample. The steps to reproduce the behavior are shown here:

 Create a default MFC or Win32 project.  Add the following lines of code along with other header files in a .cpp file. The Circ3 sample has to build before you can do this.

using namespace Circ3Lib; NOTE: You will have to provide the full path to Circ3.ocx if it isn't in your path. Also, #import by default will setup a namespace for each type library.  Build the project. At this point there will be a C2146 error.
 * 1) import "circ3.ocx"

