是在一个按纽事件
void CAMFCDlg::OnClickedSta()
{

}
中查询ACCESS:
m_pRecordset->Open("select * from hiyt",
_variant_t((IDispatch *)m_pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);‡
编译无错,但运行出现Debug Error! 调试信息为:
AfxGetThread 返回 0x00430388 class CAMFCApp theApp {CAMFCApp <错误的指针>} CWinThread *//********************************************************************************************但是改为_variant_t((IDispatch *)theApp.m_pConnection,true),肯定是不行的,请问在局部怎么用theApp?

解决方案 »

  1.   

    m_pConnection之前的操作是什么?
    为什么说_variant_t((IDispatch   *)theApp.m_pConnection,true)不行?
      

  2.   

    如果先extern   CAMFCApp  theApp;再用_variant_t((IDispatch   *)theApp.m_pConnection,true);是不是
    _ConnectionPtr m_pConnection;和AfxOleInit();都要在void   CAMFCDlg::OnClickedSta()之外而不能在局部定义和初始化?
      

  3.   

    error C2039: 'm_pConnection' : is not a member of 'CAMFCApp'
      

  4.   

    ??
    m_pConnection初始化在哪?
      

  5.   

    m_pConnection在局部(_ConnectionPtr m_pConnection;)和在A-MFCDlg.h中(public:          
      _ConnectionPtr   m_pConnection;)都一样在编译时出现:error C2039: 'm_pConnection' : is not a member of 'CAMFCApp'
      

  6.   

    你的CAMFCApp并没有m_pConnection成员阿
    自然编译出错,
    AfxOleInit();
    m_pConn.CreateInstance("ADODB.Connection");
    try{
    m_pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb","","",adConnectUnspecified);
    }catch(_com_error e){
    AfxMessageBox("连接数据库失败!");
    }
      

  7.   

    你的代码我程序里都有啊
    **************************************************************************
    _ConnectionPtr m_pConnection;
    // 初始化COM,创建ADO连接等操作
    AfxOleInit();
    m_pConnection.CreateInstance(__uuidof(Connection)); try
    {
    // 打开本地Access库
    m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hmeghy.mdb","","",adModeUnknown);
    }
    catch(_com_error e)
    {
    AfxMessageBox(L"数据库连接失败,确认数据库hmeghy.mdb是否在当前路径下!");
    return ;
    } _RecordsetPtr m_pRecordset;
    m_pRecordset.CreateInstance(__uuidof(Recordset)); try
    {
    m_pRecordset->Open("select * from hiyt",
    _variant_t((IDispatch *)theApp.m_pConnection,true),
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);
    }
    catch(_com_error *e)
    {
    AfxMessageBox(e->ErrorMessage());
    }//**********************************************************************************
    上面是写在按纽事件void CAMFCDlg::OnClickedSta(){。。}中的源码,当把_ConnectionPtr m_pConnection;取出在AMFCDlg.h中初始化时还是一样在编译时出现错误:error   C2039:   'm_pConnection'   :   is   not   a   member   of   'CAMFCApp' 
      

  8.   

    m_pConnection
    _RecordsetPtr 
    不要用局部变量
    写成对话框类的成员
      

  9.   

    在A-MFCDlg.h中这样:
    public:          
      _ConnectionPtr   m_pConnection;  不行吗?
      

  10.   

    m_pRecordset-> Open("select   *   from   hiyt", 
    _variant_t((IDispatch   *)m_pConnection,true), 
      

  11.   

    但这样写了还是有错误啊error C2039: 'm_pConnection' : is not a member of 'CAMFCApp'
            c:\documents and settings\bl\桌面\a-mfc\a-mfc.h(17) : see declaration of 'CAMFCApp'
      

  12.   

    恩?((IDispatch       *)m_pConnection?
      

  13.   

    去掉theApp不行,编译通过,但运行出现会出现Debug   Error!  调试信息为:
    AfxGetThread   返回 0x00430388   class   CAMFCApp   theApp   {CAMFCApp   <错误的指针> } CWinThread   * 
      

  14.   

    调试堆栈。。显示在appmodul.cpp的这里:
    _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    __in LPTSTR lpCmdLine, int nCmdShow)
    {
    // call shared/exported WinMain
    return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
    }hPrevInstance 0x00000000 {unused=??? } HINSTANCE__ *
    unused CXX0030: 错误: 无法计算表达式的值
      

  15.   

    代码发给我,方便的话
    [email protected]