MFC CSocket in static library
I am using the MFC class CSocket
. No big deal - open a server connection and send a short message. The code works fine when I link to the MFC in the DLL. However, the call CSocket::Create()
fails when connecting to MFC in the static library.
I would like to use MFC in a static library as it makes distribution easier.
+1
source to share
3 answers
According to http://support.microsoft.com/kb/193101
Descriptor maps used by sockets must be created for each stream. The following code shows a function for 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
}
+1
source to share