Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:07:06+00:00 2026-06-02T14:07:06+00:00

Why does SetWindowLong(myForm.hWnd, GWL_HWNDPARENT, parentHwnd) hang? I can recreate this problem consistently doing these

  • 0

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

I can recreate this problem consistently doing these three steps.

  1. Create the .NET Form
  2. Initalize the WaitWindow COM object, call ShowWindow on the COM object while passing the .NET Forms Handle
  3. 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:07:07+00:00Added an answer on June 2, 2026 at 2:07 pm

    I managed to figure out exactly what was going on and how to fix the problem. I didn’t specify my main entry point with the [STAThread] attribute so it was defaulting to MTA instead. This meant when I called the VB6 code it created a RPC Callback Thread and didn’t marshall the call to the main thread where the UI executes.

    Peter Mortensen wrote a good explanation about this:

    The STA model is used for COM objects that are not thread safe. That
    means they do not handle their own synchronization. A common use of
    this is a UI component. So if another thread needs to interact with
    the object (such as pushing a button in a form) then the message is
    marshalled onto the STA thread. The windows forms message pumping
    system is an example of this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know why this function, when passed an invalid date (e.g. timestamp) to
Does anyone know how I can implement a single Touch Event. A simple, one
Does anyone know how to make this code stop the knob from rotating past
Does this line of Perl really do anything? $variable =~ s/^(\d+)\b/$1/sg; The only thing
does someone know how I can get Sublime Text 2 to auto-hide the tabs
Does anyone know if Build.Model is stable? Can we rely on it not changing
Does the Swing API have classes which combine InputVerifiers? For example, I have three
Does anyone have any recommendations of tools that can be of assistance with moving
Does this code get called for every object creation in Java, because every object
Does anyone know what this message means (or when it raises)? CFURLCopyResourcePropertyForKey failed because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.