Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

see if handle is valid ?

Posted on 1998-03-19
5
Medium Priority
?
658 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 150 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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 extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

670 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