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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:52:22+00:00 2026-05-23T17:52:22+00:00

I am trying to implement a program that sends the same messages to a

  • 0

I am trying to implement a program that sends the same messages to a window that would be sent if a certain key is continuously pressed.
This is part of the code (entire Form1.cs code is here ) for the application:

    [DllImport("User32.dll")]
    static extern int SendMessage(IntPtr hWnd, uint wMsg, UIntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll", SetLastError = true)]
    public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle);

    private void button1_Click(object sender, EventArgs e)
    {
        // find notepad process
        System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("notepad");
        // find child handle of notepad process
        // that is where we can send WM_KEYDOWN, WM_CHAR and WM_KEY up messages to write in the window
        IntPtr childHandle = FindWindowEx(p[0].MainWindowHandle, IntPtr.Zero,"Edit", IntPtr.Zero);

        // WM_KEYDOWN message with parameters for 1st key
        SendMessage(childHandle, (uint)0x0100, (UIntPtr)0x00000041, (IntPtr)(0x001E0001));
        // WM_CHAR message with parameters for 1st key
        SendMessage(childHandle, (uint)0x0102, (UIntPtr)0x00000061, (IntPtr)(0x001E0001));

        // WM_KEYDOWN message with parameters for n-th key
        SendMessage(childHandle, (uint)0x0100, (UIntPtr)0x00000041, (IntPtr)(0x401E0001));
        // WM_CHAR message with parameters for n-th key
        SendMessage(childHandle, (uint)0x0102, (UIntPtr)0x00000061, (IntPtr)(0x401E0001));

        // WM_KEYUP message
        SendMessage(childHandle, (uint)0x0101, (UIntPtr)0x00000041, (IntPtr)(0xC01E0001));
    }

Upon reaching the WM_KEYUP SendMessage in the code the program crashes and gives the error:

How can i fix this error?
The 4 SendMessage calls before the WM_KEYUP one work ok and they send 2 letter ‘a’ to notepad.

Thanks for your replies

  • 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-05-23T17:52:23+00:00Added an answer on May 23, 2026 at 5:52 pm

    I assume you are compiling for x86. On x86 targets, 0xC01E0001 is not a valid IntPtr value (the maximum is 0x7FFFFFFF).

    2 options here :

    • You do use the value lParam in the target application. In this case you have to use another value for the IntPtr, or use the type UIntPtr (but this type is not CLS-compliant).
    • You do not use the value lParam in the target application. In this case just pass IntPtr.Zero as lParam.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am trying to implement a Java program which sends an Apple Push Notification to
I'm trying to implement a program that changes a prefix expression to a postfix
I am trying to implement simple program in Java that will be used to
I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current
I'm trying to implement a program which runs a function limited by a fixed
I am trying to implement a very basic before advice with Spring.Net, that just
I am trying to implement a paint program in PyQt4. In the QGraphicsScene, I
I'm trying to convert a GUI program that uses .png images into an .exe
Hi i'm trying to create a sever/client program that takes up to 5 clients
In a program that I'm trying to write now I take two columns of

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.