?
Solved

win32exception error creating window handle.

Posted on 2009-05-02
7
Medium Priority
?
1,379 Views
Last Modified: 2013-12-17
Hello Experts:
Today  seems to be a bad day for me... my time and effort are running out.

Having this scenario:
There is three Forms, First one appears as DialogBox and hides the second form (a child form).. asks the user to enter a password and if its correct then the first form (the DialogBox one) will close and the second form will appeare as a child in the thired form which is MDI form.

the problem is when a valid passowrd is enterd an win32Exception thrown. and if an invalid password entered in the first form (or cancel was clicked) an exception will says "Value Dispose() cannot be called while doing CreateHandle().".

See the attached picture. which demonstrates the state.

Thanks in advance for any help persists here.
Saed Salman
101.jpg
0
Comment
Question by:SaedSalman
  • 4
  • 3
7 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 24290131
I face this problem as well. The trouble is, when you try to call the close method of the form in the load method of the form, it contradicts with each other. Try showing the login form in the Shown method of the main form instead of the loading method.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 2000 total points
ID: 24290134
Another way is to load the login form only and if the login is correct then create the main form, instead just close the login form.
0
 
LVL 6

Author Comment

by:SaedSalman
ID: 24290259
You are amazing CodeCruiser, this will solve the problem but I got ride of the problem already.
What I did is not to re-place login form to the main method instead of load method BUT I removed the call of loginForm.Hide() and loginForm.Show() in the child form.
here is a code snippet:
Initialize() method is called in the load method of the child form. Please take a look and give me your opinon, I already you will not like my silly programming style, this is the way I performe login phase :)

Note that the twice call of Form.Show() is reason of the problem:
I called Show() method in the child form which will display the login form then I called Show() method in the MDI Parent form which will display the child form. (Am I right? Why ?)
private void Initialize()
        {
            bool flag=false;
            try
            {
                //this.Hide();
                ConnectDB x = new ConnectDB();// create the login form
                DialogResult result = x.ShowDialog();
                if (result == DialogResult.OK)
                {
                    flag = true;
                    connstr = x.ToString();
                    con = new OracleConnection(connstr);
                    con.Open();
                    x.Close();
                    x.Dispose();
                    //this.Show();
                    FillFields();
                }
                else
                {
                    flag = false;
                    x.Close();
 
                    if (this.IsMdiChild)
                        this.MaximizeBox = false;
                    else
                        this.Dispose();
                    //Application.Exit();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "Loging in...",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if ((flag) && (con.State!=ConnectionState.Open))
                    Initialize();// recursion call
            }
        }

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24290269
Does it work ok now?
0
 
LVL 6

Author Comment

by:SaedSalman
ID: 24290280
Yes it is :)
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24290306
The code seems ok.
0
 
LVL 6

Author Closing Comment

by:SaedSalman
ID: 31577171
Thank you for your time, Your help is much appreciated.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question