Solved

see if handle is valid ?

Posted on 1998-03-19
5
636 Views
Last Modified: 2013-12-03
GetExitCodeThread(pReadingThread->m_hThread, &ExitCode);
 
when I use it as above, I sometimes crash as debugger tells:

pReadingThread      0x00dddb50 {CWinThread h=??? proc=???}

so how should I check if pReadingThread->m_hThread is
valid ?
0
Comment
Question by:has
5 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1412113
There is no way to test if a thread handle is valid, but I suspect the problem is that pReadingThread is a bad pointer, not that pReadingThread->m_hThread is a bad handle.
0
 
LVL 1

Expert Comment

by:rayofunreal
ID: 1412114
Hi all...

Dear niethod, I think there is a function to do this. It is called GetHandleInformation(HANDLE hObj,DWORD* flg);
I don't know if it works with all handles, but I think yes. If no, reject me :-)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1412115
That returns information about the object referenced by the handle.  It does work on all valid handles, but it does not test if a handle is valid.  I suspect that if you pass it a bad handle the results will probably be unpredicatable.  That is, it won't always returns an error.  You might want to test this, however.  Create and then destoy something and then test the handle with this procedure.  To be safe you need to do a bunch of tests under different circumstances.
0
 

Author Comment

by:has
ID: 1412116
gethandleinformation will fail too, but saving
pReadingThread->m_hThread to a variable when thread starts
then using it in getexitcodethread will work, as stefanr
suggests, so I will give the credit to him, when he answers
my question again here, thanks.
0
 
LVL 11

Accepted Solution

by:
alexo earned 50 total points
ID: 1412117
There are APIs to check whether a memory block is valid.  Try the IsBad{something}Ptr() family of functions.  Ffor example, IsBadReadPtr().

First, check pReadingThread, then m_hThread (handles are actually pointers, as you can see in the windows include files).

A different approach can be using the Win32 Structured Exception Handling and catching the exception that crashes your program.  See the help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now