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 8466581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:22:59+00:00 2026-06-10T15:22:59+00:00

I’m trying to communicate with a native library that uses an HWND to pass

  • 0

I’m trying to communicate with a native library that uses an HWND to pass messages back to the caller as follows:

private void Example()
{
    using (
        var hwnd = new HwndSource(
            new HwndSourceParameters("I sense a disturbance in the force...") {HwndSourceHook = WndProc}
            )
        )
    {
        //send hwnd.handle to native library
        while (true) { }
    }
}

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool ishandled)
{
    ishandled = false;
    Console.WriteLine("Intercepted message: 0x{0:X}", msg);
    return IntPtr.Zero;
}

Even when the call the the native library is omitted, I only ever receive the following messages (in order):

  1. 0x0001: WM_CREATE
  2. 0x0018: WM_SHOWWINDOW
  3. 0x0046: WM_WINDOWPOSCHANGING
  4. 0x0046: WM_WINDOWPOSCHANGING
  5. 0x001C: WM_ACTIVATEAPP
  6. 0x0086: WM_NCACTIVATE
  7. 0x007F: WM_GETICON
  8. 0x007F: WM_GETICON
  9. 0x007F: WM_GETICON
  10. 0x0006: WM_ACTIVATE
  11. 0x0281: WM_IME_SETCONTEXT
  12. 0x0282: WM_IME_NOTIFY
  13. 0x0007: WM_SETFOCUS
  14. 0x0085: WM_NCPAINT
  15. 0x0014: WM_ERASEBKGND
  16. 0x0047: WM_WINDOWPOSCHANGED
  17. 0x0083: WM_NCCALCSIZE
  18. 0x0085: WM_NCPAINT
  19. 0x0014: WM_ERASEBKGND
  20. 0x0005: WM_SIZE
  21. 0x0003: WM_MOVE
  22. 0x000D: WM_GETTEXT

After this I can drag the window corresponding to the HwndSource around but am unable to resize or close it. Furthermore the operating system claims that this window is not responding.

Why does this window stop responding and how can I continue to intercept messages?

  • 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-10T15:23:00+00:00Added an answer on June 10, 2026 at 3:23 pm

    As both @HansPassant and @HassanBoutougha pointed out the issue is with the following segment of code:

    while (true) { }

    While this may look like it’s innocently keeping the application alive what it’s really doing is preventing the dispatcher from processing messages. The messages that I was seeing was because they were being called directly from within the thread executing Example() by the HwndSource constructor. After construction the application enters the loop and runs around in circles. Unfortunately this is the thread that’s suppose to be processing the messages!

    Essentially the correct solution here was to tell the dispatcher to put the current call stack on the back burner and process events until we tell it to stop.

    DipatcherFrame frame = new DispatcherFrame();
    Dispatcher.PushFrame(frame);
    

    Essentially the call to Dispatcher.PushFrame this tells the dispatcher to suspend execution and continue listening to messages. At some point in the future if you decide that you want to resume execution where you left of just do the following:

    frame.Continue = false;
    

    And that’s it! The call to Dispatcher.PushFrame will now return and resume execution

    Kent Boggart has a great example here: http://kentb.blogspot.ca/2008/04/dispatcher-frames.html
    Unfortunately Kent’s blog is no longer available however a snapshot of the page from Google’s cache may be found here.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

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.