|
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.
|
|
|
|
|
Hi all,
I intend to filter IPv6 packets.
I have already succeeded in capturing and decoding the packets n a human readable format.
Now i want to block some unwanted IPv6 traffic
say:
I do Win XP to drop packets with destination address A and port A1 and source address B and port B1
how can I do this?
will manipulating the IPv6 routing tables on my machine work?
I did
C:> netsh
netsh> interface ipv6
interface ipv6> show routes
this showed me some routes for IPv6 traffic going out of my machine,can i manipulate them to block certain traffic.
Is there any other way of doing it, are there some libraries,classes, methods that can help filtering IPv6 packets.
please help
thanks and regards
Ather
|
|
|
|
|
Don't cross post.
led mike
|
|
|
|
|
I've managed to compile and run all the samples in the book so far, but all the sudden this code comes up and gives me nasty headaches.
When i'm trying to compile the code below everything goes fine until the compiler tries to link it.
Here's the error i get:
cd /Users/summer/Documents/C++/xcodeproject/ex<br />
/Developer/usr/bin/g++-4.0 -o /Users/summer/Documents/C++/xcodeproject/ex/build/Debug/ex -L/Users/summer/Documents/C++/xcodeproject/ex/build/Debug -F/Users/summer/Documents/C++/xcodeproject/ex/build/Debug -filelist /Users/summer/Documents/C++/xcodeproject/ex/build/ex.build/Debug/ex.build/Objects-normal/i386/ex.LinkFileList -arch i386 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk<br />
Undefined symbols:<br />
"vtable for Kvadrat", referenced from:<br />
__ZTV7Kvadrat$non_lazy_ptr in main.o<br />
ld: symbol(s) not found<br />
collect2: ld returned 1 exit status<br />
"vtable for Kvadrat", referenced from:<br />
__ZTV7Kvadrat$non_lazy_ptr in main.o<br />
ld: symbol(s) not found<br />
collect2: ld returned 1 exit status
And here's the code:
#include <iostream>
using namespace std;
class Form
{
public:
Form() {}
virtual ~Form() {}
virtual long HentAreal() { return -1; }
virtual long HentOmkreds() { return -1; }
virtual void Tegn() {}
};
class Rektangel : public Form
{
public:
Rektangel(int laengde, int bredde):
densLaengde(laengde), densBredde(bredde) {}
virtual ~Rektangel() {}
virtual long HentAreal() { return densLaengde * densBredde; }
virtual long HentOmkreds() { return 2*densLaengde + 2*densBredde; }
virtual int HentLaengde() { return densLaengde; }
virtual int HentBredde() { return densBredde; }
virtual void Tegn();
private:
int densBredde;
int densLaengde;
};
void Rektangel::Tegn()
{
for (int i = 0;i < densLaengde;i++)
{
for (int j = 0;j < densBredde;j++)
cout << "x";
cout << "\n";
}
}
class Kvadrat : public Rektangel
{
public:
Kvadrat(int laengde);
Kvadrat(int laengde, int bredde);
~Kvadrat();
long HentOmkreds() { return 4 * HentLaengde(); }
};
Kvadrat::Kvadrat(int laengde):
Rektangel(laengde, laengde)
{}
int main()
{
cout << "Do stuff";
return 0;
}</iostream>
When i remove
Kvadrat::Kvadrat(int laengde):<br />
Rektangel(laengde, laengde)<br />
{}
It compiles without problems. But i want to create a rectangel upon creation of a square! (rektangel == rectangel && kvadrat == square in danish)
|
|
|
|
|
You need a body for Kvadrat 's destructor.
"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
|
|
|
|
|
wow.. that was too simple. i feel stupid.
thanks!
|
|
|
|
|
you forgot:
Rektangel class default constructor (declaration & definition).Kvadrat(int laengde, int bredde) constructor definition.Kvadrat destructor definition
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
You beat me to it, you addict.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|