PRB: Conflict with EOF When Using #import with ADO

Last reviewed: January 30, 1998
Article ID: Q166112
The information in this article applies to:
  • ActiveX Data Objects (ADO) included with: - Microsoft Visual C++, 32-bit Editions, versions 4.2, 5.0

SYMPTOMS

With #import, it is possible to generate classes that encapsulate the typelib of database API's, such as ActiveX Data Objects (ADO), within a windows application. For example:

   // Excerpt from Stdafx.h
   #include <afxwin.h>         // MFC core and standard components
   ...
   #import "C:\Program Files\Common Files\System\ADO\Msado10.dll"

When doing so, you may receive the following errors from the #import for ADO on the Recordset.EOF property:

   error C2629: unexpected 'short ('
   error C2238: unexpected token(s) preceding ';'

NOTE: The same error occurs with ADO version 1.5 using Msado15.dll.

CAUSE

Within an application that uses STDIO.H, IOS.H or STREAMB.H (including AFXWIN.H ), EOF has already been defined as a constant (-1). #import then attempts to define the EOF property for ADO's Recordset or RDO's Resultset objects, and generates the C2629/C2238 errors on this line of generated code in the MSADO10.TLH file:

   VARIANT_BOOL EOF;

This line is attempting to define a variable, but EOF has already defined it as -1. As a result, this line of code parses to:

   short -1;

This does not compile because -1 is not a valid variable name.

RESOLUTION

To correct this, you can use the rename attribute of #import as shown below:

   #import "C:\Program Files\Common Files\System\ADO\msado10.dll" \
           rename( "EOF", "A_EOF" )

Rename changes the name of any "EOF" string that #import finds in the specified typelib to a new value.

NOTE: When you use ADO version 1.5, replace Msado10.dll with Msado15.dll.

Keywords          : kbprg adoengall adoengdb adovc MfcDatabase
Version           : 5.0
Platform          : NT WINDOWS
Issue type        : kbprb


================================================================================


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: January 30, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.