From: "Paul Rzepecki" <Paul on
Hi,
I'm trying to write activex control with mfc which connect to the another
app through socket. The socket conn form activex to the app is made on a
different thread.
The thread is initialize by function:

HANDLE threadHandle = CreateThread(NULL,NULL,
(LPTHREAD_START_ROUTINE)ThreadProc,
(LPVOID)this, NULL, &dwID);

and everything works correct except this that i,m tryin to connect from
another instance of this activex i get CResourceexception. Anu ideas how to
avoid this?

CSocket is declare localy and in ThreadProc is no loops or any similar things.

Any Ideas?
From: Joseph M. Newcomer on
First, forget CSocket exists. It is always a mistake to use it (among other misfeatures,
the implementation is reported to have serious bugs). Use CAsyncSocket, always.

You are also using CreateThread, which is almost certainly a serious mistake. If this is
in MFC, you should use AfxBeginThread. CreateThread works ONLY if your code uses NO MFC
and NO C runtime library, which seems unlikely since you are using CSocket. Because
critical MFC data structures, such as those required for CSocket, are not properly
initialized, I wouldn't even try to figure out what was going wrong until the more
fundamental problem was fixed.

Get rid of the (LPTHREAD_START_ROUTINE) cast as well. It allows you to compile programs
that can't run.
joe

On Thu, 30 Jun 2005 04:45:02 -0700, "Paul Rzepecki" <Paul
Rzepecki(a)discussions.microsoft.com> wrote:

>Hi,
>I'm trying to write activex control with mfc which connect to the another
>app through socket. The socket conn form activex to the app is made on a
>different thread.
>The thread is initialize by function:
>
>HANDLE threadHandle = CreateThread(NULL,NULL,
> (LPTHREAD_START_ROUTINE)ThreadProc,
> (LPVOID)this, NULL, &dwID);
>
>and everything works correct except this that i,m tryin to connect from
>another instance of this activex i get CResourceexception. Anu ideas how to
>avoid this?
>
>CSocket is declare localy and in ThreadProc is no loops or any similar things.
>
>Any Ideas?

Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Scott McPhillips [MVP] on
Paul Rzepecki wrote:
> Hi,
> I'm trying to write activex control with mfc which connect to the another
> app through socket. The socket conn form activex to the app is made on a
> different thread.
> The thread is initialize by function:
>
> HANDLE threadHandle = CreateThread(NULL,NULL,
> (LPTHREAD_START_ROUTINE)ThreadProc,
> (LPVOID)this, NULL, &dwID);
>
> and everything works correct except this that i,m tryin to connect from
> another instance of this activex i get CResourceexception. Anu ideas how to
> avoid this?
>
> CSocket is declare localy and in ThreadProc is no loops or any similar things.
>
> Any Ideas?

AfxBeginThread must be used to create the thread. You must use the
version that has a RUNTIME_CLASS argument, so you will have a thread
that provides the MFC messsage pump that CSocket requires. Also,
CAsyncSocket is far more reliable than CSocket.

There is a sample application in MSDN named MFCAsync that shows how to
do all this.

--
Scott McPhillips [VC++ MVP]

 | 
Pages: 1
Prev: UTF-8
Next: VFW, webcam, image format