道物业从VB到MFC

时间:2018-06-29 18:57:16

标签: mfc vb6 ado dao

我已经在c ++中实现了vb功能,我已经在c ++中替换了以下逻辑,但是却出现了问题:

我必须从VB转换为c ++,并且在获取属性时c ++中的代码崩溃。

原始VB代码:

For Each loTDef In aoDBUser.TableDefs

          Set loProp = Nothing
          On Error Resume Next
          Set loProp = loTDef.Properties("Description")

          If Not loProp Is Nothing Then
               If loProp.Value = TEMP_TABLE Then
               End If
          End If
     Next 

新的C ++代码:

CString test::Property()
{
    //
    // OVERVIEW:
    // Get the value for the given Custom Property
    //
    DAOProperties *pColProp = NULL;
    DAOProperty *pProp = NULL;

    CDaoDatabase cDBase;
    cDBase.Open(CV_GetUserDatabasePath(_T("TEST.mdb")));

    CString strDbVer;
    DAOProperties* pPrp = 0;
    DAOProperty* pRev = 0;
    try
    {
        if ( !cDBase.IsOpen() )
            return(_T(""));

        DAO_CHECK(cDBase.m_pDAODatabase->get_Properties(&pPrp));
        if ( pPrp != 0 )
        {
            COleVariant varRevVal;
            COleVariant varName(_T("Description"), VT_BSTRT);

            DAO_CHECK(pPrp->get_Item(varName, &pRev));//crashing going to catch 

            if (pRev != 0)
            {
                DAO_CHECK(pRev->get_Value(&varRevVal));
                pRev->Release();
                pRev = 0;
            }
            pPrp->Release();
            pPrp = 0;

            strDbVer = V_BSTRT(&varRevVal);
        }
    }
    catch (...)
    {

    }

    cDBase.Close();
}

它在DAO_CHECK(pPrp->get_Item(varName, &pRev));中崩溃的方式

但是我不知道为什么会这样。

0 个答案:

没有答案