1.如果是设置为在Dll中使用MFC那么一切正常,如果将工程设置为在静态库中使用mfc,
  那么当执行
  m_ListenSocket.Create(8000);
  时出错,在跟踪下去最终在CAsyncSocket::LookupHandle处出现异常,为什么?2.我程序中用到了数据库spl,用的是ADO,将工程设置为在Dll中使用MFC,在.net2008下运行一切正常,但是
直接双击可执行程序时,出现错误,"连接数据库出错,错误代码:IDispatch error:#3194

解决方案 »

  1.   

    2. try catch 捕获 一下数据库操作的异常,查看错误信息..
      

  2.   

    1、把执行m_ListenSocket.Create的代码提前执行,例如放在类的构造函数里面,看看是否出错,如果不出错,再逐步往后放,确认一下在执行了什么错误后执行该代码会出错。
    2、注意相对路径的问题。
      

  3.   

    第一个问题解决了,解决方法如下:(我是在一个子线程中调用 m_ListenSocket.Create(8000))
    只要在包含套接口的线程的CListenThread::InitInstance()中添加如下代码:
            #define _afxSockThreadState AfxGetModuleThreadState()
    #define _AFX_SOCK_THREAD_STATE AFX_MODULE_THREAD_STATE _AFX_SOCK_THREAD_STATE* pState = _afxSockThreadState;
          if (pState->m_pmapSocketHandle == NULL)
             pState->m_pmapSocketHandle = new CMapPtrToPtr;
          if (pState->m_pmapDeadSockets == NULL)
             pState->m_pmapDeadSockets = new CMapPtrToPtr;
          if (pState->m_plistSocketNotifications == NULL)
             pState->m_plistSocketNotifications = new CPtrList;
    就没问题了,我看不懂上面的代码,请大家帮我分析下.2.第二个问题还没解决.我吧ado要到的文件msado15.dll放到了工程下面,然后在程序中
    #import ".\msado15.dll" no_namespace rename("EOF","adoEOF")
    也还是出错.(保证不是密码,用户名出错,因为直接在.net下是可以运行的,就只有双击可执行程序时出错)
      

  4.   

    2. 双击时,你打印一下出错的信息提示,MessageBox等捕捉一下,所有的数据库相关操作需要加上try ..catch
      

  5.   

    1. msdn上有描述
    FIX: Unhandled Exception Using MFC Sockets in Visual C++ 6.0  
    The information in this article applies to:
    The Microsoft Foundation Classes (MFC), when used with:
    Microsoft Visual C++, 32-bit Enterprise Edition 6.0
    Microsoft Visual C++, 32-bit Professional Edition 6.0
    Microsoft Visual C++, 32-bit Learning Edition 6.0  
    Symptoms
    When using MFC sockets in secondary threads in a statically linked MFC Visual C++ 6.0 application, an unhandled exception occurs.
    Cause
    The reason for the unhandled exception is that an object of type CMapPtrToPtr pointer, pointed to by m_pmapSocketHandle, is never created.
    Resolution
    The handle maps used by the sockets need to be created for each thread. The following code shows a function to do this:void SocketThreadInit() 

    #ifndef   _AFXDLL 
    #define   _AFX_SOCK_THREAD_STATE   AFX_MODULE_THREAD_STATE 
    #define   _afxSockThreadState   AfxGetModuleThreadState() 
        _AFX_SOCK_THREAD_STATE*   pState = _afxSockThreadState; 
        if(pState->m_pmapSocketHandle == NULL) 
            pState->m_pmapSocketHandle = new CMapPtrToPtr; 
        if(pState->m_pmapDeadSockets == NULL) 
            pState->m_pmapDeadSockets = new CMapPtrToPtr; 
        if(pState->m_plistSocketNotifications == NULL) 
            pState->m_plistSocketNotifications = new CPtrList; 
    #endif 
    }
    This function should be called once in each secondary thread before the first socket is created in the new thread.
    在每个线程开始出调用SocketThreadInit函数,就没有问题了
      

  6.   

    请大家帮忙看下这个帖子.
    http://topic.csdn.net/u/20090321/18/c04f2a26-00ef-4d9c-8c5a-88faced15490.html?seed=545397319
      

  7.   

    数据库问题也解决了,我用了配置文件,配置文件要放在Debug文件夹下面才可以