Socket and thread
-
Hello I create a CSocket object then I post it to a thread but when I post it to thread, posted object(pointer) is not valid in thread how can I create a socket out of thread and send it to thread? thanks Mehrdad
Your question does not seem to be very clear. How do you create the CSocket object? If it is like:
CSocket sock; ...Initialize it etc. CreateThread(... , (void*)&sock...); //etc
Then it is not going to work, because the object is being created on the stack and will be destroyed when the calling function exits. Create it on the heap etc:CSocket* pSock; pSock = new CSocket; ...Initialize it etc.
Then send it to the thread. Hope that helps. this is this. -
Hello I create a CSocket object then I post it to a thread but when I post it to thread, posted object(pointer) is not valid in thread how can I create a socket out of thread and send it to thread? thanks Mehrdad
Many types of MFC objects can't be passed between threads becaues MFC keeps per-thread data structures. Pass the
SOCKET
handle to the thread then callCSocket::FromHandle()
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ