SetWindowLong Hanging

Why SetWindowLong(myForm.hWnd, GWL_HWNDPARENT, parentHwnd)does it freeze?

I can recreate this problem sequentially by following these three steps.

  1. Create a .NET Form
  2. Initialize the WaitWindow COM object, call ShowWindow on the COM object when passing the .NET form descriptor
  3. In VB6, call the SetWindowLong method

C # Windows app (freezes)

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 (does not freeze)

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 understand that SetWIndowLong should not be called to change the parent, but I'm trying to understand why it hangs only when using the .NET form descriptor.

EDIT2

, SetWindowLong, . , , VB6 .NET, RPC. , , - .

+4
3

, . [STAThread], MTA MTA. , VB6, RPC- , .

:

STA COM, . , . . , (, ), STA. .

+3

MSDN

SetWindowLong GWL_HWNDPARENT, . SetParent.

+2

Are you running this on a 64-bit system? Does your VB6 application have a 32-bit application? If you fall into this scenario, this will explain why the RPC call is being created, and this will explain why your illegal hacking does not work. If so, the bad news is that now you can make it work.

You should also be aware that the underling window handle for the .net control can change throughout the duration of the control . See Also this question in SO for a discussion of this question.

+1
source

All Articles