Error Creating Window Handle

"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

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值