473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

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.

Nov 14 '05 #1
1 6518
ph*****@yahoo.com 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
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
3
by: mccanaveras | last post by:
Hello, I need to implement a Thread in a Visual C++ 6.0 application. I've never done this, then I've been investigating, but I don't have any properly solution. One of them is use CWinThread...
3
by: Pinux | last post by:
Hi, I am writing a multi-threads encryption application. The idea of the code is to create a number of threads to encrypt files. I have a thread pool say the maximum threads is 10. If the number...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
1
by: =?Utf-8?B?SkI=?= | last post by:
Newbie on threads. Maybe I am the only person around that doesn't understand this but what happens when the threadproc returns? ( new Thread (addressof threadproc)... etc.) I have looked in the...
3
by: sevak316 | last post by:
This must be an easy question. I am trying to create a thread in windows. I am using C as my language. I am trying to pass a function to the CreateThread function to create a thread. My...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.