|
I don't see anything documented anywhere about Win32 threads having names.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The Last parm on CreateThread I thought that was a pointer to somehow Identifying the thread ...... (below)
I have a Windows Internals Book I am going to see if with a thread Handel I can somehow Identify the Thread
pThreadId
A pointer to a variable that receives the thread identifier. If this parameter is NULL, the thread identifier is not returned.
Return Value
|
|
|
|
|
ForNow wrote: The Last parm on CreateThread I thought that was a pointer to somehow Identifying the thread
Yes, it is the unique identifier for the thread. You can also get it with GetCurrentThreadId(),
as I mentioned in my first reply.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
So SO Sorry ... You know people tell me this all the time My Boss or When I am dating
I just don't listen or read
Thankx
|
|
|
|
|
ForNow wrote: or When I am dating
Who listens to them anyway hehe
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
GetCurrentThreadId() is useful to get the unique identifier for the thread.
The WMI Win32_Thread class has a little info - not much useful except for thread state.
To set the thread name seen in the debugger: How to: Set a Thread Name in Native Code[^]
I'm not sure how one gets the thread name programatically.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
To set a thread name while debugging, as Mark mentioned:
void utl::SetThreadName( cchar *NAME, DWORD ID )
{
struct {
DWORD Type;
cchar *Name;
DWORD Id;
DWORD Flags;
} info = { 0x1000, NAME, ID, 0 };
__try
{
::RaiseException(0x406D1388, 0, sizeof(info)/sizeof(DWORD), (ULONG_PTR*)&info);
}
__except(EXCEPTION_CONTINUE_EXECUTION)
{
}
}
There is no way to get the name back.
If you really want to associate a name with a thread then use some variant of TLS.
When you get the THREAD_ATTACH is fairly well spelled out in the MSDN docs, what part don't you understand ?
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
Hi, and thankx for responding
What my problem is that in my DLL_ATTACH_THREAD I only want to process only certin threads in my app So. I want to have some way of identfying them (the threads)
How about PsGetCurrentThread The seems to return a pointer to a ETHREAD block where I could some how identify from where this thread originated from
even though it was probably itended for device drivers the doc says any IRQL level
Thankx
|
|
|
|
|
Just use the thread handle and thread id from either:
GetThreadId(thread_hnd)
GetCurrentThreadId()
From MSDN:
Until a thread terminates, its thread identifier uniquely identifies it on the system.
This means you must also track when a thread you are interested in dies.
For threads you start you can just catch DLL_THREAD_DETACH.
For others (e.g. started by MS CRT or nVidia OpenGL driver) you won't always get a DLL_THREAD_DETACH.
ForNow wrote: some how identify from where this thread originated from
This is an unrelated issue, if you want to know that use StackWalk64 to trace the call stack.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
|
I like StackWalk64 is there 32 bit version ??
|
|
|
|
|
I have a dialog based app. In the OnInitDialog() function I am showing for some time a dialog box without any buttons and system menu. It shows a waiting message. It appears into the upper left corner of the screen. How can I make it apper centred to the screen?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Use CenterWindow() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You can use of David's answer or set CenterWindow to true of property window.
|
|
|
|
|
Hi all,
i want to use a bitmp variable as a global var,
so i wrote this code
<br />
CNeLoPApp theApp;<br />
CBitmap bitmap;<br />
bitmap.LoadBitmap(IDB_BITMAP1);<br />
HBITMAP hBitmap = (HBITMAP) bitmap.GetSafeHandle();<br />
But i had those errors
error C2143: syntax error : missing ';' before '.'
error C2501: 'bitmap' : missing storage-class or type specifiers
error C2371: 'bitmap' : redefinition; different basic types
error C2143: syntax error : missing ';' before '.'
Whayt's wrong with that code.
PS: i wrote nthq into the stdafx.h
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Blood_HaZaRd wrote: bitmap.LoadBitmap(IDB_BITMAP1);
HBITMAP hBitmap = (HBITMAP) bitmap.GetSafeHandle();
Where are you calling these methods from?
Blood_HaZaRd wrote: error C2143: syntax error : missing ';' before '.'
What line?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I changed some lignes:
in the stdafx.h
<br />
extern CBitmap bitmap;<br />
extern HBITMAP hBitmap ;<br />
In myprog.cpp (where 'TheApp' var is declared by default )
<br />
bitmap.LoadBitmap(IDB_BITMAP1);<br />
hBitmap = (HBITMAP) bitmap.GetSafeHandle();<br />
but now on aform when i try to set the bitmap to a button via OnInitialUpdate()
<br />
m_Next.SetBitmap(hBitmap);<br />
I have this error
: error C2065: 'hBitmap' : undeclared identifier (that hBitmap is not declared on that form)
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Ok i foud the solution.
all that i do is to delete the debug folder and rebuild the prog. and it works.
But I still have some issue:
when i run the prog the button dosn't display the bitmap. but when i move the window or clik on it the bitmap appears. I even put the m_Next.SetBitmap(hBitmap); into the OninitialUpdate() and OnPaint().
how ciould i resolve that little prob
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
There's no reason to extract the HBITMAP from a CBitmap into a separate variable.
The handle is available from the CBitmap object any time.
That aside, you need to separate the global variable definitions from the code that
initializes them. For example:
CNeLoPApp theApp;<br />
CBitmap bitmap;<br />
HBITMAP hBitmap = NULL;<br />
<br />
BOOL CNeLoPApp
::InitInstance()<br />
{<br />
bitmap.LoadBitmap(IDB_BITMAP1);<br />
hBitmap = (HBITMAP) bitmap.GetSafeHandle();
...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I had to declare The bitmap and hBitmap as global var coz i had to Forms A & B and in both of them i hve a buttom that uses the same bitmap but when i goback from B to A the prog crashes (Erreur and stops).
So with global vars i had no more the erreur. but when i lunch tha prog, i have to wait 3 or 4 seconds to viex the button with the bitmap (may be it's a time prob for loading the bitmap).
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
First, CBitmap is a C++ wrapper for an HBITMAP handle. To have a separate HBITMAP variable
is redundant and instantly doubles your maintenance for a single object. There's NO valid reason
for doing that. You can use your CBitmap object anywhere a HBITMAP is needed, without even having
to cast it, because CBitmap has a HBITMAP cast operator.
Second, why not take advantage of the object-orientedness of MFC and encapsulate the
bitmap object in the class that uses it? What makes you think two buttons can safely share the
same bitmap?
There's rarely a need for global variables in MFC. If you think you need a global variable, there's
probably a better way to design your code.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have 2 forms on each of which i load the same bitmap for a button (let's say a button labeled Next).
when i load the bitmap and the Hbitmap on form A all go well
when i load the form B after a click on button from form A all go well
when i wanna goback to form A aftr a clik on a button on Form B the prog Crach down. That's why i used the bitmap and the hBitmap as global var?
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
How do you know the crash is related to the bitmap?
If it is taking 3-4 seconds to load a bitmap, it's either really big, or
there's a problem somewhere else.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You can also use of HBITMAP without CBitmap.
|
|
|
|