Solved

see if handle is valid ?

Posted on 1998-03-19
5
657 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 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