Solved

see if handle is valid ?

Posted on 1998-03-19
5
656 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 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