strange run time error notification (empty pop-up window)  
Author Message
Peter__Pan





PostPosted: Visual C++ General, strange run time error notification (empty pop-up window) Top

When a run time error occurs (e.g. an invalid file handle is used) in a console application created in debug mode with C++ Express Edition I get a completely empty pop-up window (title reads "Microsoft Visual C++ Debug Library") with three empty buttons. Clicking on any button terminates the application.

1.) Is this behaviour due to the missing C debug runtime libraries in EE (i.e. is it a "feature")
2.) Running the same .exe in an environment with .net 2002 installed shows the usual window contents and I am able to run the de**** - it points to the bad statement
I use /MTd (link runtime lib statically) - how comes the pop-up window is fully working

Any help highly appreciated



Visual C++2  
 
 
JamesSexton





PostPosted: Visual C++ General, strange run time error notification (empty pop-up window) Top

Peter__Pan,

My guess is your CreateFile() [-obsolete: OpenFile()-] came back with an INVALID_HANDLE_VALUE,
which often happens when:

1) file's path is not exact
2) file does not exist
3) file already open

Therefore, try() and catch() your CreateFile() function and do something if its handle comes
back an INVALID_HANDLE_VALUE before jumping into some DialogBox. Why If you hit on a null
pointer and attempt to read or write on it, then your program already crashed...

That your popup DialogBox works in 2002 and not in 2005 may mean the file is located in your
2002 directory's path and not within its 2005's path.

Whatever, Run Time Errors (usually null pointers) are serious stuff. I doubt your problem has
anything to do with Microsoft's debug or release modes or Visual Studio's versions 2002-2005.

Try something simple like:

handle=CreateFile(etc...);
if (handle == INVALID_HANDLE_VALUE || handle == NULL)
{
;//DON'T go to DialogBox
}
else
{
;//go to DialogBox and have fun...
}


JamesSexton



 
 
Simple Samples





PostPosted: Visual C++ General, strange run time error notification (empty pop-up window) Top

When CreateFile returns INVALID_HANDLE_VALUE, I would not call that a runtime error. There are many other terms that could be used to refer to it, but for here, I will call it necessary diagnostics; that is, checking for an error is necessary diagnostics. A runtime error is what you get when you don't do necessary diagnostics. You could report it as a bug if the Express Edition does not report a meaningful message when the handle is INVALID_HANDLE_VALUE, but be aware that the problem is less important if it happens only when a previous error is ignored.



 
 
Simple Samples





PostPosted: Visual C++ General, strange run time error notification (empty pop-up window) Top

if (handle == INVALID_HANDLE_VALUE || handle == NULL)
A handle is not a pointer and the documentation does not state explicitly whether a null handle is invalid, therefore we should assume it is valid. I don't know what the value of INVALID_HANDLE_VALUE is, but if it is not zero then zero could be a valid handle value; if it is zero then it is redundant to check for both INVALID_HANDLE_VALUE and NULL.

 
 
JamesSexton





PostPosted: Visual C++ General, strange run time error notification (empty pop-up window) Top

Simple Samples,

True, INVALID_HANDLE_VALUE is not very clear. It used to be NULL in the 80's and 90's. You can find the definition in WINBASE.H

#define INVALID_HANDLE_VALUE (HANDLE)-1

Microsoft says when CreateFile() fails : "If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError"

Also True, a HANDLE is not exactly what you would call a pointer but a "Handle to an object" whatever that means. No matter, when you try to
open, read, write and/or close an INVALID_HANDLE_VALUE you got something like NULL pointer. Maybe my terms are not exactly cricket, but the end
results sure seem to be...

I'm signing off... (see you later)
JamesSexton alias "OldTimer Samples"




 
 
Simple Samples





PostPosted: Visual C++ General, strange run time error notification (empty pop-up window) Top

Yes, I did look at the definition of INVALID_HANDLE_VALUE before posting my reply. My reply was intended to be an explanation of how to use the function as it is documented. The intent of symbolics such as INVALID_HANDLE_VALUE is to make us independent of meaningless numbers. We often do have to look at what the values actually are, but we should use the symbolic names whenever it is possible to develop with them and we should not use values if we can use symbolics instead. My reply was intended to be consistent with that.