Microsoft KB Archive/152387

{|
 * width="100%"|

SAMPLE: DAOPROP.EXE: DaoProp Uses MFC Properties Collection
'Article ID: Q152387

Creation Date: 12-JUN-1996

Revision Date: 21-FEB-1997' The information in this article applies to:


 * The Microsoft Foundation Classes (MFC), included with: Microsoft Visual C++, 32-bit Edition, versions 4.0, 4.1

SUMMARY

DAOPROP.EXE demonstrates how to extract information from the Properties collection, which is not supported by the MFC DAO classes. In particular, it demonstrates how to get a list of properties and how to add a property.

In order to properly manage variants, DAOPROP.EXE utilizes #defines and classes defined in the DAO SDK. You will want to install the DAO SDK and note the includes and pragmas in STDAFX.H in order to properly link with the DAO SDK.

The following file is available for download from the Microsoft Software Library:

~ Daoprop.exe (size: 42091 bytes) For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base: ARTICLE-ID: Q119591 TITLE    : How to Obtain Microsoft Support Files from Online Services NOTE: Use the -d option when running DAOPROP.EXE to decompress the file and recreate the proper directory structure. MORE INFORMATION

Many DAO objects contain Properties collections but, to date, MFC does not wrap the interface functions to extract properties. The following excerpts from DAOPROP show how to get to the DAO interfaces and obtain properties.

For more information on installing and using the DAO SDK, please see the following article in the Microsoft Knowledge Base:

ARTICLE-ID: Q149392 TITLE    : How to Use the DAO SDK dbDao Classes with Visual C++ 4.x Sample Code

The following code demonstrates how to get the list of properties from a given DAO object, and how to create a new property:

void CDaoPropDlg::OnButton1 {    CDaoDatabase db; db.Open( PATH_TO_MDB_FILE ); CDaoTableDef td( &db ); td.Open( TABLE ); DAOProperties* prps; DAOProperty* prp; COleVariant var;

TRY {        td.m_pDAOTableDef->get_Properties( &prps ); int i=0; m_ListBox.ResetContent;

while( prps->get_Item( COleVariant( (short)i++, VT_I2 ), &prp ) == S_OK ) {            prp->get_Value( &var );

if( var.vt == VT_BSTR || var.vt == VT_BSTRT ) if( strlen( ( LPCTSTR ) var.bstrVal ) > 0 ) m_ListBox.AddString( ( LPCTSTR )var.bstrVal ); }    }     CATCH ( CDaoException, e ) {        AfxMessageBox( e-> m_pErrorInfo->m_strDescription ); }    END_CATCH

UpdateData(FALSE); td.Close; db.Close;

}

void CDaoPropDlg::OnButton2 {    CDaoDatabase db; db.Open( PATH_TO_MDB_FILE ); CDaoTableDef td( &db ); td.Open( TABLE ); DAOProperty* prp; DAOProperties* prps;

UpdateData( TRUE );

if( m_propname.GetLength == 0 ) {        AfxMessageBox( "Please enter Property Name" ); return; }

if( m_propval.GetLength == 0 ) {        AfxMessageBox( "Please enter Property Value" ); return; }

DAO_CHECK(td.m_pDAOTableDef->CreateProperty( STV( m_propname  ), OLTV( dbText ), VTV( m_propval ), BTV( 0 ), &prp));

if( FAILED( td.m_pDAOTableDef->get_Properties( &prps ) ) ) {        AfxMessageBox( "get_Properties Failed" ); goto term; }

if( FAILED( prps->Append( prp ) ) ) {        AfxMessageBox( "Append Failed" ); goto term; }

term: prp->Release; prps->Release; td.Close; db.Close; }
 * }

-

 KBCategory: kbprg kbole kbfile kbcode

KBSubcategory: MfcDAO MfcDatabase kbsample

Additional reference words: 4.00 4.10 prop

"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." '' ©1997 Microsoft Corporation. All rights reserved. Legal Notices.

''