1.如果是设置为在Dll中使用MFC那么一切正常,如果将工程设置为在静态库中使用mfc,
那么当执行
m_ListenSocket.Create(8000);
时出错,在跟踪下去最终在CAsyncSocket::LookupHandle处出现异常,为什么?2.我程序中用到了数据库spl,用的是ADO,将工程设置为在Dll中使用MFC,在.net2008下运行一切正常,但是
直接双击可执行程序时,出现错误,"连接数据库出错,错误代码:IDispatch error:#3194
那么当执行
m_ListenSocket.Create(8000);
时出错,在跟踪下去最终在CAsyncSocket::LookupHandle处出现异常,为什么?2.我程序中用到了数据库spl,用的是ADO,将工程设置为在Dll中使用MFC,在.net2008下运行一切正常,但是
直接双击可执行程序时,出现错误,"连接数据库出错,错误代码:IDispatch error:#3194
2、注意相对路径的问题。
只要在包含套接口的线程的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下是可以运行的,就只有双击可执行程序时出错)
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函数,就没有问题了
http://topic.csdn.net/u/20090321/18/c04f2a26-00ef-4d9c-8c5a-88faced15490.html?seed=545397319