Accessing ADO with Visual C++
Visual C++ is a much more difficult language and environment with which to develop applications for ActiveX Data Objects. Because it is so difficult, Microsoft is constantly trying to provide developers with easier ways to access ADO components.
By far the easiest method (and the only method described here) is one
that takes advantage of the
#import
keyword. This approach offers not only the most control to the
developer, but it also allows the developer to code in a Visual Basic
programming style.
Referencing ActiveX Data Objects
The
#import
keyword is used in Visual C++ applications
to import information from a type library. To make ADO.ACcessible to
your C++ code, use the following #import
directive:
#import <msado15.dll> no_namespace rename("EOF", "EOFile")
This statement assumes that the path to msado15.dll (usually C:\Program Files\Common Files\System\ADO) is already set within the Visual C++ environment; if not, select the Directories tab of the Options dialog box (Tools → Options), and add it.
The #import
statement does a couple of things.
First, at compile time it creates a header file with a
.tlh extension, which stands
for
Type Library Header.
This header file is comprised of enumerated types and definitions for
the objects contained in the type library for
msado15.dll.
Secondly, it creates a file with a .tli (Type Library Implementation) extension that contains the wrappers for each function in the object model defined by the msado15.dll ...
Get ADO: ActiveX Data Objects now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.