I am developing an extension for existing application via COM.
Current interface of the application to extend allows to create custom property windows and use them inside that application.
Now, I am using .NET for that purpose and have strange problems:
extensionForm = new Form();
extensionForm.SetBounds(0, 0, 100, 100);
extensionForm.Controls.Add(new Button());
ExApplAPI.AddCustomPropertyWindow(extensionForm.Handle.ToInt32(), "Ololo");
As you can see below, the property sheets actually get extended, but after that something strange starts to happen.

Basically, if I switch to Ololo tab, then back to any of other 3 tabs (Attributes, Drawing or Services), the application freezes. I also know that the freeze happens inside of some unmanaged code block.
Another interesting fact here is that if I don’t write the extensionForm.Controls.Add(new Button()) (with or without the Suspend / Resume Layout calls), everything works fine. So, if the recently constructed form has no controls (buttons or any other) on it, it doesn’t freeze.
Here is a Spy++ log on the Ololo window right before the freeze (last message is the WM_CTLCOLORBTN, right after that the application became frozen):

Combining everything together:
- Freezing happens only if I switch from
Ololoto some other tab and then switch to theOlolotab again. - Freezing only happens if the integrated form has at least one control on it, forms without controls don’t freeze.
- Application is not running any managed code at the moment and is not spending any CPU time.
So – any ideas / similiar problems solved / etc to help me in this case?
The Win32
HWNDhandles for the Forms in .NET are lazy initialized.And I think this may be a problem here.
You may argue that the handle is created in your line
ExApplAPI.AddCustomPropertyWindow(extensionForm.Handle.ToInt32(), "Ololo");due to accessingHandleproperty.It is true and what documentation acknowledges.
However, it creates the handle for the
Formitself, but handles for child controls (Buttonin this case) are not created. This can be forced by callingCreateControlmethod. See more documentation.I don’t know if not having a handle for button may be a cause of your problem, but this is definitely something I would investigate.
To summarize, I suggest changing your code to: