Error Creating Window Handle

来源:互联网 发布:阿里巴巴串货到淘宝卖 编辑:程序博客网 时间:2024/06/06 01:57

"Error Creating Window Handle" This is one of the more aggravating errors in Windows programming. I think even worse than a VB6 favorite “Object ~ does not exist.“ I got it today when loading a form that is part of a VS2003 app I converted to VS2005. It took me a while to get to the bottom of why this error was being thrown (during debugging and also on a client machine) since it's coming from Win32, not .NET.

In my case, it turned out that the culprit had something to do with setting icons, though this wasn't obvious because I could step through even that section of code with no problems. The error was thrown after the form had run through it's load method and on it's way back to the line of code that instantiated the form. Oddly, it was method call that did not even need to be there, possibly an accidental copy/paste at some point. But it's been in the VS2003 version for a long time and has caused no problems. When I deleted the particular code (happy to have such an easy out!), everything worked again.

So, in hindsight, it all makes perfect sense. VS2005 and .NET 2.0, as I have noted in previous posts (having learned the hard way), is much more sensitive about UI threading issues. This is a GOOD thing and has helped me clean up some code that VS2003 let me get away with (more lack of understanding than anything). Icons are image files - a.k.a. unmanaged objects. So even though I wasn't getting anything helpful regarding where the problem was coming from and what the problem was exactly, the clues were all there.

”Error Creating Window Handle” is a Win32 error, therefore the first thing I should have been looking at was any code that did anything with unmanaged items. I did actually think of that early on, but overlooked that particular method call and went on a wild goose chase for a while.

So to recap, kids....

Problem: Error Creating Window Handle
First thing to look for: Anything that might be related to unmanaged code - streams, bitmaps, ink, etc.

Additional things to look for (I will keep adding to this list if you want to send me items, like JFo did!)

  • “You can get this if you override the WndProc and forget to call base - my personal pet error.” (Jessica Fosler, Microsoft formerly on the WinForms team)

 转自:http://thedatafarm.com/devlifeblog/archive/2006/02/22/40253.aspx

 
原创粉丝点击