Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > ThreadProc does not run when CreateThread() is called within a DLL.

Reply
Thread Tools

ThreadProc does not run when CreateThread() is called within a DLL.

 
 
phark52@yahoo.com
Guest
Posts: n/a
 
      04-08-2005
My main app calls LoadLibrary() to load a DLL, which calls
CreateThread(). This does NOT return NULL and I get a thread ID.
However, ThreadProc never gets executed when this code is in the DLL.
It works fine in the standalone EXE source.

I put example code below.

#define MB(msg) MessageBox(0, msg, "", MB_OK|MB_ICONINFORMATION);

DWORD APIENTRY tproc() {
for(;
MB("hi from tproc");
return 0;
}

BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
{
HANDLE h;
DWORD id;
MB("Creating thread...");
h=CreateThread(0, 0, tproc, 0, 0, &id);
if (!h) { MB("Thread creation failed."); exit(1); }
// tproc should run now and display msg boxes over and over..
for(;;
exit(0);
}


There is something in MSDN.. can someone translate this for me? I don't
understand. I thought initializing happens in DllMain. How do I tell
Windows that initialization is done?

Quote:
Do not create a thread while impersonating another user. The call will
succeed, however the newly created thread will have reduced access
rights to itself when calling GetCurrentThread. The access rights
granted are derived from the access rights that the impersonated user
has to the process. Some access rights including
THREAD_SET_THREAD_TOKEN and THREAD_GET_CONTEXT may not be present,
leading to unexpected failures.

* During process startup and DLL initialization routines, new threads
can be created, but they do not begin execution until DLL
initialization is done for the process.
* Only one thread in a process can be in a DLL initialization or detach
routine at a time.
* ExitProcess does not return until no threads are in their DLL
initialization or detach routines.

 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      04-08-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
> My main app calls LoadLibrary() to load a DLL, which calls
> CreateThread(). This does NOT return NULL and I get a thread ID.
> However, ThreadProc never gets executed when this code is in the DLL.
> It works fine in the standalone EXE source.


I see no mention of LoadLibrary, DLL, CreateThread, etc. in the C
standard. I.E. this is off-topic in c.l.c. Follow-ups set.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does Code in a Separate Thread Have to be in a <run()> or Called by a <run()>? KevinSimonson Java 7 10-18-2010 06:39 PM
Why is a button Click event also called when a textbox TextChanged event is called??? S_K ASP .Net 6 11-08-2007 07:44 PM
What is called carry chain structure in FPGA is called in IC? Weng Tianxiang VHDL 6 09-12-2007 07:19 AM
When does Runnable.run called sakcee@gmail.com Java 1 05-17-2007 05:59 PM
three times copy ctor called, one ctor called, why? Apricot C++ 4 04-16-2004 07:55 AM



Advertisments