views:

110

answers:

5

Every Windows developer is all too familiar with an alert of the form:

Foo.exe has encountered a problem and needs to close.

I am resigned to my apps blowing up from time to time (only during development of course), but when they do, I don't want to see "Foo.exe" here. I want to see a "friendly" name such as "FooBrowser™".

I've searched the MSDN documentation high and low for a way to override this string and not found it. And I've conducted lots of experiments to see if I could stumble across the mechanism without any luck. However, when I search the web for "has encountered a problem and needs to close", I see lots of folks discussing instances preceded by a friendly name, and I doubt they're all replacing the entire alert with their own. :-)

I need this to work for native Win32 applications; .NET ain't an option. The set of examples I see discussed on the web includes Microsoft Internet Explorer (a native app) and Microsoft Works (which I assume is still a native app although it's been four eons since I saw it).

What's the secret handshake?

A: 

Could you not create a simple string resource that contains the friendly name of your application and use that when formatting the message?

What do you think?

Hope this helps, Best regards, Tom.

tommieb75
This message is not posted by my app; it's posted by Windows. My code is not in control.
Integer Poet
@Integer Poet: Have you tried a shortcut link to the application? I am shooting myself in the foot on this and taking a long pot shot on that... :(
tommieb75
Creating a shortcut with a friendly name doesn't help.IShellLink supports a shortcut description which might be of use. It's theoretically possible that asking Windows Explorer to open a shortcut with a description would cause the use of some undocumented interface to set the friendly name of the process, but I doubt it.It might be worth investigating despite my doubt, except that I don't have the option of asking Windows Explorer to launch processes by indirecting through shortcuts because I already have existing code I can't change which calls CreateProcess.
Integer Poet
+1  A: 

Why not just rename your application executable FooBrowser™.exe?

Roddy
Too many other programs depend on the EXE filename staying the same.
Integer Poet
As well, the ".exe" is part of the problem.
Integer Poet
+1  A: 

hmm. I don't know if this is for sure what will do it, but it's worth a try. Try looking into SetCurrentProcessExplicitAppUserModelID

Matt
Looks unrelated.
Anon.
That API is used to control how windows are grouped together on the taskbar (different taskbar items for windows from same process or one taskbar item for multiple processes.)
Michael
+2  A: 

My understanding is that once your exception bubbles up to the OS, you're out of luck. My approach would be to catch the exception before it reaches the OS. In my applications, I have a form that I show when I have an unhandled exception that allows the user to submit bug reports, preventing the OS from showing the form you're talking about.

Just a different perspective :)

Charlie Salts
SEH __catch is something I've been pondering, so thanks for confirming that it's a viable approach.
Integer Poet
Note that it is risky to run code in the context of a crashed process. You can register with MS to receive the crash data from your app that users send in.
Michael
@ Michael - Possibly risky, yes. I code mostly in C# so I have a try...catch around my Application.Run(). Unmanaged apps might be a little different. As for registering with MS... was not aware of that!
Charlie Salts
But, usually the "%s has encountered a problem" dialog boxes are a result from an unrecoverable error such as an memory access violation (e.g. null pointer dereference). These aren't catchable exceptions . . . or are they?
dreamlax
Unmanaged apps are incredibly different - with a managed exception in .NET you can still trust the CLR. For a native crash you can only trust the kernel, which is incredibly limiting in what you can do. For some exceptions you can't even trust that you have a valid stack to run on.http://www.microsoft.com/whdc/winlogo/maintain/StartWER.mspx describes how to access crash data from MS.
Michael
@dreamlax - only a few exceptions are uncatchable (for example, security related exceptions.) Access violations you can catch. Not that you should.
Michael
MSDN documentation indicates they are catchable via SEH __catch, which is different from C++ catch.
Integer Poet
+3  A: 

I'm not sure exactly what version of Windows you are targeting, but newer ones will try to use the friendly product name when you crash.

Make sure you add a version resource to your executable, and provide a friendly product name and file name, in the FileDescription string.

This page on MSDN provides more information.

Michael
I've tried many many strings in the version resource and none seems to have the desired effect. As well, the string "Microsoft Internet Explorer" appears nowhere in its version resource, yet this string does appear in its crash alerts (according to the web -- I haven't seen it crash lately myself).
Integer Poet
Oh, and I need to support XP 32 SP3. Which of the version strings would you expect to be used for the "friendly" name? This page doesn't seem to say I should expect any of them to work:http://msdn.microsoft.com/en-us/library/ms646987(VS.85).aspx
Integer Poet
Internet Explorer (what appears in crash dialogs) most assuredly appears in the version resource of IE, I just took a look at it. What OS are you targeting, and can you include the relevant snippet from your .RC file.
Michael
I believe FileDescription is the relevent string.
Michael
According to the web, the string which appears in the crash alert for MSIE is "Microsoft Internet Explorer" rather than "Internet Explorer". I found this string encoded as UTF-16 in the data within the code image, so I'm guessing it might come from there.
Integer Poet
http://img.photobucket.com/albums/v256/abercombre/vista1error.jpg is a picture of the crash screen and shows Internet Explorer in the string.
Michael
FileDescription is used by Windows 7 though not Windows XP 32 SP3. Sadly, Windows XP is still very important.
Integer Poet
Works under Vista as well. This looks like it might be the best answer. I really could use a solution for XP, though.
Integer Poet