Microsoft Knowledge Base

BETA-BUG: C2059: syntax error : 'for' with #import mshtml.dll

Last reviewed: April 30, 1997
Article ID: Q167657
************************************************************************* CONFIDENTIAL BETA CONFIDENTIAL BETA CONFIDENTIAL BETA CONFIDENTIAL

This article discusses a beta test product not yet released by Microsoft. Please feel free to familiarize yourself with this product, test it, and report problems to Microsoft.

CONFIDENTIAL BETA CONFIDENTIAL BETA CONFIDENTIAL BETA CONFIDENTIAL *************************************************************************

The information in this article applies to:

  • Microsoft Internet Explorer (Programming), version 4.0

SYMPTOMS

When using the #import compiler directive to import Mshtml.dll, several errors similar to the following are reported:

   \MSHTML.tlh(4159) : error C2059: syntax error : 'for'
   \MSHTML.tlh(4159) : error C2238: unexpected token(s) preceding ';'
   \MSHTML.tlh(8707) : error C2059: syntax error : 'for'
   \MSHTML.tlh(8707) : error C2238: unexpected token(s) preceding ';'

CAUSE

These errors are generated because of the following code:

   IHTMLLabelElement : IHTMLElement
   {
       //
       // Property data
       //

       __declspec(property(get=Getname,put=Putname))
       _bstr_t name;
       __declspec(property(get=Getfor,put=Putfor))
       _bstr_t for;
   ...

The errors are a result of "for" being a reserved keyword in C++.

RESOLUTION

The rename attribute of the #import directive is used to work around name collision problems.

Use #import with Mshtml.dll as follows:

   #import "C:\WINNT\system32\MSHTML.DLL" rename("for", "LEfor")

It is not necessary to use LEfor--any non-reserved name will do.

NOTE: To reference IHTMLLabelElement::for in your project, you will need to refer to IHTMLLabelElement::LEfor.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

REFERENCES

Visual C++ Preprocessor Reference, the #import directive


Keywords : AXSDKIESripting
Version : 4.00
Platform : WINDOWS
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1997
©1997 Microsoft Corporation. All rights reserved. Legal Notices.