PRB: Conflict with EOF When Using #import with ADO

ID: Q166112


The information in this article applies to:


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 <msado15.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 ';'


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). The #import then attempts to define the EOF property for ADO's Recordset or RDO's Resultset objects, and generates the C2629/C2238 errors on the following 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 follows:


   #import <msado15.dll>
    rename( "EOF", "A_EOF" ) 

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

Another fix is to undefine EOF before importing ADO follows:

#undef EOF
#import <msado15.dll> rename_namespace("ADO20") 


STATUS

This behavior is by design.

Additional query words: kbdsd KBadovc


Keywords          : kbprg kbDatabase 
Version           : WINDOWS:
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: March 12, 1999