From: Jim Johnson on
why if I have used MFC in my EXE - then I cannot use

_beginthread / _beginthreadex?

to create a thread?

I seem to hear someone said so earlier...
From: Doug Harrison [MVP] on
On Wed, 16 Apr 2008 17:34:24 -0700, Jim Johnson <aopiyy001(a)yahoo.com>
wrote:

>why if I have used MFC in my EXE - then I cannot use
>
>_beginthread / _beginthreadex?
>
>to create a thread?
>
>I seem to hear someone said so earlier...

If your thread uses MFC, it's best to use AfxBeginThread, and for some
guidance on using it correctly, see:

http://members.cox.net/doug_web/threads.htm

Also, the existence of _beginthread should be ignored; always use
_beginthreadex instead of _beginthread, because the former returns the
thread handle and doesn't auto-delete it. That's important for the same
reasons as described in Q1 and Q2 in the cited article.

--
Doug Harrison
Visual C++ MVP
From: Scott McPhillips [MVP] on
"Jim Johnson" <aopiyy001(a)yahoo.com> wrote in message
news:6m6d0496ufdtd7l89vi6tj1nbv9jdjkc6q(a)4ax.com...
> why if I have used MFC in my EXE - then I cannot use
>
> _beginthread / _beginthreadex?
>
> to create a thread?
>
> I seem to hear someone said so earlier...

MFC relies on some thread-local variables and state. AfxBeginThread
initializes those, then calls _beginthreadex for you. Just part of the
preconditions for using the library. If you don't use AfxBeginThread some
of your calls to MFC functions could encounter uninitialized pointers.

--
Scott McPhillips [VC++ MVP]

From: Jim Johnson on
What if I am creating a DLL with function like

XMLClass::DownloadData(){
// create a new thread here for as Download takes 10mins
_beginthreadex( //my thread entry point);
}


But I am not sure if my friend's application using my DLL is going to
use MFC or not.

Then should I use AfxBeginThread or _beginthreadex in my DLL library
function???


>
>MFC relies on some thread-local variables and state. AfxBeginThread
>initializes those, then calls _beginthreadex for you. Just part of the
>preconditions for using the library. If you don't use AfxBeginThread some
>of your calls to MFC functions could encounter uninitialized pointers.
From: Scott McPhillips [MVP] on
"Jim Johnson" <aopiyy001(a)yahoo.com> wrote in message
news:ovld04l00vru0lee29hrtjhlhbiv90123a(a)4ax.com...
> What if I am creating a DLL with function like
>
> XMLClass::DownloadData(){
> // create a new thread here for as Download takes 10mins
> _beginthreadex( //my thread entry point);
> }
>
>
> But I am not sure if my friend's application using my DLL is going to
> use MFC or not.
>
> Then should I use AfxBeginThread or _beginthreadex in my DLL library
> function???


You should use AfxBeginThread if, and only if, your DLL uses MFC. The
calling exe is irrelevant to this.

--
Scott McPhillips [VC++ MVP]

 | 
Pages: 1
Prev: return string
Next: return value