Why does SetWindowLong(myForm.hWnd, GWL_HWNDPARENT, parentHwnd)
hang?
I can recreate this problem consistently doing these three steps.
- Create the .NET Form
- Initalize the WaitWindow COM object, call ShowWindow on the COM object while passing the .NET Forms Handle
- In VB6 invoke the SetWindowLong method
C# Windows Application (Hangs)
private static void Main(string[] args)
{
Form form = new Form();
form.Show();
Interop.WaitWindow waitWindow = new Interop.WaitWindow();
waitWindow.ShowWindow(form.Handle.ToInt32(), Language.RISEnglish);
}
C# Console Application (Doesn't Hang)
private static void Main(string[] args)
{
IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
Interop.WaitWindow waitWindow = new Interop.WaitWindow();
waitWindow.ShowWindow(handle.ToInt32(), Language.RISEnglish);
}
VB6 Code Snippet
Public Sub ShowWindow(ByVal parentHwnd As Long, ByVal language As Language)
SetWindowLong(myForm.hWnd, GWL_HWNDPARENT, parentHwnd) 'Hangs Here
CenterWindow (parentHwnd)
myForm.ShowRetrieving (language)
myForm.Show (vbModal)
End Sub
Really would appreciate your help :)
EDIT
I do understand that SetWIndowLong shouldn't be called to change the parent but I'm trying to understand why it hangs only when a .NET form handle is used.
EDIT2
I now believe the issue is not related to SetWindowLong but the actual handle itself. I'm still investigating but it appears that when I call the VB6 code from .NET it creates an RPC thread. I'm not sure yet but I have a feeling it has something to do with a cross-threading issue.