Microsoft KB Archive/237285

= SAMPLE: Daoprop.exe Sets a Custom Property on an Access Database with MFC DAO =

Article ID: 237285

Article Last Modified on 8/5/2004

-

APPLIES TO


 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q237285



SUMMARY
The Daoprop.exe sample demonstrates how to add a custom property to a Microsoft Access database by using the Microsoft Foundation Class Library (MFC) Data Access Objects (DAO) classes and the underlying DAO OLE interfaces.

The sample is based on another Microsoft Knowledge Base article, which demonstrates the same concept by using Microsoft Visual Basic for Applications in Microsoft Access 97. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

178745 ACC: Using DAO to Set and Retrieve Custom Database Properties

The MFC DAO classes directly expose a subset of the DAO hierarchy. However, the MFC DAO classes do not expose all of the functionality that is available to developers who are using Microsoft Visual Basic, Visual Basic for Applications, or the DAO Software Development Kit (SDK) in Visual C++. It is possible to use the complete hierarchy indirectly by using the underlying DAO OLE interfaces that the MFC DAO classes wrap.



MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

Daoprop.exe

Release Date: Sept. 7, 2000

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. The Daoprop.exe sample contains the following files:

The DAO interfaces are defined in the Dbdaoint.h file in the VC98\Include folder. When you use the DAO OLE interfaces, it is often necessary to use the VARIANT and BSTR data types. These data types can be conveniently manipulated by using the wrapper class COleVariant. To initialize a VARIANT object with a BSTR string, use the VT_BSTRT type specified to ensure that the string is created as an ANSI string in ANSI builds, and as a Unicode string in Unicode builds. For additional information about strings and DAO, click the article number below to view the article in the Microsoft Knowledge Base:

140599 PRB: MFC DAO Functions Accepting COleVariant Strings May Fail

For a demonstration of how to initialize a COleVariant object and extract values from it, see the DAOVIEW sample in the Microsoft Developer Network (MSDN).

The project included in the self-extracting executable is an MFC single document project. Its functionality is contained in the three menu handlers OnPropertyCreate, OnPropertyGet, and OnPropertySet. These functions call the CreateCustomProp, GetCustomProp, and SetCustomProp functions, respectively.

Several concepts are demonstrated by this sample:
 * Creating a COleVariant of type VT_BSTRT in OnPropertyCreate and OnPropertyGet.
 * Using the V_BSTRT macro to extract a string from a COleVariant in OnPropertyGet.
 * Using the DAO OLE interfaces in CreateCustomProp, GetCustomProp, and SetCustomProp.
 * Using the DAO_CHECK macro to test the success of a DAO call and throw an exception in case of failure.
 * Using the TRY, CATCH_ALL, END_CATCH_ALL and THROW_LAST macros to correctly handle exceptions when using the DAO OLE interfaces.

To check the custom property in your Access database file, open the file in Access 97, on the File menu, click Database Properties, and then click the Custom tab.

