Microsoft KB Archive/167657

= 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.