Question

vb.net Error creating window handle

Asked by: delphikit

Hi All expert,
I have no ideal why and when this error happen every day. I cannot similate the error. Do your have any ideal?

Error creating window handle.System.Windows.FormsSystem.ComponentModel.Win32Exception: Error creating window handle.
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Control.get_Handle()
   at System.Windows.Forms.Control.CreateGraphicsInternal()
   at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
   at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
   at System.Windows.Forms.ThreadContext.OnThreadException(Exception t)
   at System.Windows.Forms.Control.WndProcException(Exception e)
   at System.Windows.Forms.ControlNativeWindow.OnThreadException(Exception e)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at System.Windows.Forms.Form.ShowDialog()

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-04-16 at 21:53:29ID21815887
Tags

window

,

creating

,

error

,

handle

Topics

Miscellaneous Programming

,

Signal Processing

Participating Experts
4
Points
500
Comments
13

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Question about LPARAM , WPARAM etc
    A simple theory question (I think). LPARAM , RPARAM , WPARAM etc. What are these?? Using them in my code if I look at them all I see is a value (number) yet somehow this "value" will contain a number I need but can;t see anywhere. ie :OnClickListcontrol(NMHDR* pNM...
  2. How to pass a CString variable through a LPARAM or WPA…
    I was wondering how to pass a CString variable through a postmessage LPARAM or WPARAM. Ive tried to cast it but it still says no.
  3. SendMessage - Clarification on Properly Using the WPARA…
    I am planning on using the wparam and lparam parameters of SendMessage to send small bits of data between two Windows applications on the same machine. The types and forms of the data are as follows: * int - between four to six digits * string - between two to three charac...
  4. LParam and WParam convert UINT_PTR to LONG_PTR
    I'm new to this and want to know some info about LParam and WParam. I have a SendMessage() call that uses the same character pointer for WParam and LParam e.g. char* someName; SendMessage(somevar,somevar,(WPARAM)someName, (LPARAM)someName); and I receive these values in a ...
  5. Retreve a Hicon handle from a HWND handle
    I need a function written in VB.net (win32 API) that takes a HWND handle and returns that windows Icon as a Hicon handle. Please help! Here's What I Got: 'Defines Const GWW_HINSTANCE = (-6) Dim hinstance As IntPtr Dim i Dim hicon As IntPtr ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: NeoEGMPosted on 2006-04-16 at 22:37:45ID: 16467202

It's probably because a lack of memory... Try to cleanup as much as you can of what you allocate...

Take a look at this:
http://www.google.com/search?q=cache:wCsVCwJJajMJ:thedotnet.com/howto/work245730.aspx+%22Error+creating+window+handle%22+VB.NET&hl=es&gl=ar&ct=clnk&cd=9

Regards,
NeoEGM

 

by: gherguPosted on 2006-04-17 at 00:59:00ID: 16467581

Hello!

The problem is that your application is creating too many objects (windows NT/XP has a limit of 10,000 windwos handles per process). Try to redesing your application in order to create only the required objects for a certain step. Also, try to avoid to use too many global objects.

 

by: delphikitPosted on 2006-04-17 at 01:11:49ID: 16467608

Dear NeoEGM,

It could be this reason. Anywhere I will try it 1st. But i notice that the memory Usage always go between 40k to 60k. Is there any where to cut it down?

 

by: NeoEGMPosted on 2006-04-17 at 01:28:08ID: 16467645

A way to know more about your process is by going to Windows Task Manager->"Processes" tab->"View" menu->Select columns->Check:

- USER objects
- Handle Count
- Thread Count
- GDI Objects

You should try to keep them as low as possible...

Don't worry so much about the memory usage of the .NET Framework... VB.NET uses to allocate lots of memory and it isn't always a problem... you should reduce the amount of handles/objects in use; it's the best place to start from...

Regards,
NeoEGM

 

by: delphikitPosted on 2006-04-17 at 02:02:05ID: 16467720

Dear NeoEGM,

Thank you again for your reply. I had tested few transaction in my application and this is the result i get from the Windows Task Manager.
 USER objects = 307
 Handle Count =485
 Thread Count =11
 GDI Objects =679

It is normal?.. What is the limit for thoese usage?

Thanks

 

by: NeoEGMPosted on 2006-04-17 at 02:18:42ID: 16467754

Dear dephikit,

It don't know what kind of application you're developing, but I dare to say that the GDI Objects, the USER Objects and the Handle Count are too high...

If I were you I'd take a look at all my code to see if I close all the handles I open/get, if I free all the GDI objects I get allocated and if I do the needed cleanup after any operation I finish...

Probably, when those values get higher, the app will throw the error you described...

Keep monitoring the values as you do specific operations on your app and try to cleanup your code as much as you can...

Regards,
NeoEGM

 

by: jobrienctPosted on 2006-04-17 at 03:32:06ID: 16468105

FYI. I was getting this error repeatedly and intermittently as well. I was not creating any wnew window handles, the only window was the single dialog.  but for my application I would, for each file in a queue...

a. position the cursor offscreen
b. lock the cursor using a windows API
c. call an external application that I also wrote

It was this context swtching that caused the problem, occasionally a vibration would cause the mouse to try to move while it was closing the external application and switching back to my dialog application - outside of the context of my application the mouse was no longer locked, if it was moving when it switched back i somethimes got this error. By disabling the mouse lock the problem completely disappeared.

So it was while my window was taking the focus that this error occurred for me and you should be aware that it can be dificult to determine the root cause. I have put it down as a dotnet foible.

John

 

by: SStoryPosted on 2006-04-17 at 13:01:17ID: 16472054

You aren't by any chance placing a private class in the form1.vb file above the definition of the form are you?  This has bitten me before, but I don't recall the error message.

 

by: delphikitPosted on 2006-04-17 at 20:28:18ID: 16474739

Hi Jobrienct,

How to position the cursor offscreen and how to lock the cursor using windows API?
Can you send me the code how to do that?

Thanks,

 

by: jobrienctPosted on 2006-04-18 at 09:27:36ID: 16479557

sure, sounds a bit OT for your Q but ...

Dim iWidth As Integer = 720
Dim iHeght As Integer = 480
Cursor.Position = PointToScreen(New Point(iWidth + 10, iHeight + 10))

will position your cursor off and to the bottom right of your screen. I use an API to set the screen resolution when the prgram starts.

more later

 

by: jobrienctPosted on 2006-04-18 at 10:12:56ID: 16479964

In declarations add:

Friend Mouse As New MouseTrap

Then use the following class to disable...

Mouse.Dsable()

or enable...

Mouse.Enable()

your mouse - which either allows or disallows mouse movements while your application has the focus.

Public Class MouseTrap

#Region "Declarations - Constants"

    Private Const HC_ACTION As Integer = 0
    Private Const WH_MOUSE_LL As Integer = 14
    Private Const WM_MOUSEMOVE As Integer = &H200
    Private Const WM_LBUTTONDOWN As Integer = &H201
    Private Const WM_LBUTTONUP As Integer = &H202
    Private Const WM_LBUTTONDBLCLK As Integer = &H203
    Private Const WM_RBUTTONDOWN As Integer = &H204
    Private Const WM_RBUTTONUP As Integer = &H205
    Private Const WM_RBUTTONDBLCLK As Integer = &H206
    Private Const WM_MBUTTONDOWN As Integer = &H207
    Private Const WM_MBUTTONUP As Integer = &H208
    Private Const WM_MBUTTONDBLCLK As Integer = &H209
    Private Const WM_MOUSEWHEEL As Integer = &H20A

#End Region

#Region "Declarations - Structures"

    Private Structure POINT

        Private x As Integer
        Private y As Integer

    End Structure

    Private Structure MSLLHOOKSTRUCT

        Private pt As POINT
        Private mouseData As Integer
        Private flags As Integer
        Private time As Integer
        Private dwExtraInfo As Integer

    End Structure

#End Region

#Region "Declarations - Win32 API's"

    Private Declare Function SetWindowsHookEx Lib "user32" _
        Alias "SetWindowsHookExA" ( _
        ByVal idHook As Integer, _
        ByVal lpfn As LowLevelMouseProcDelegate, _
        ByVal hmod As Integer, _
        ByVal dwThreadId As Integer) As Integer

    Private Declare Function CallNextHookEx Lib "user32" ( _
        ByVal hHook As Integer, _
        ByVal nCode As Integer, _
        ByVal wParam As Integer, _
        ByVal lParam As MSLLHOOKSTRUCT) As Integer

    Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
        ByVal hHook As Integer) As Integer

#End Region

    Private hhkLowLevelMouse As Integer

#Region "Declarations - Functions"

    Private Function LowLevelMouseProc( _
        ByVal nCode As Integer, _
        ByVal wParam As Integer, _
        ByVal lParam As MSLLHOOKSTRUCT) As Integer

        If (nCode = HC_ACTION) Then

            If wParam = WM_MOUSEMOVE Or _
                wParam = WM_LBUTTONDOWN Or _
                wParam = WM_LBUTTONUP Or _
                wParam = WM_LBUTTONDBLCLK Or _
                wParam = WM_RBUTTONDOWN Or _
                wParam = WM_RBUTTONUP Or _
                wParam = WM_RBUTTONDBLCLK Or _
                wParam = WM_MBUTTONDOWN Or _
                wParam = WM_MBUTTONUP Or _
                wParam = WM_MBUTTONDBLCLK Or _
                wParam = WM_MOUSEWHEEL Then

                Return 1

            End If

            Return CallNextHookEx(hhkLowLevelMouse, _
                nCode, wParam, lParam)

        End If

    End Function

    Private Delegate Function LowLevelMouseProcDelegate( _
        ByVal nCode As Integer, _
        ByVal wParam As Integer, _
        ByVal lParam As MSLLHOOKSTRUCT) As Integer

#End Region

#Region "Declarations - Mouse Public Class Methods"

    Public Sub Disable()

        'Set MouseTrap
        hhkLowLevelMouse = SetWindowsHookEx(WH_MOUSE_LL, _
            AddressOf LowLevelMouseProc, _
            Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, _
            0)

    End Sub

    Public Sub Enable()

        'Release MouseTrap
        UnhookWindowsHookEx(hhkLowLevelMouse)

    End Sub

#End Region

End Class ' Class MouseTrap

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...