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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:28:29+00:00 2026-05-27T19:28:29+00:00

I have an application that will form a packet and send the packet data

  • 0

I have an application that will form a packet and send the packet data to an external program to send. I have everything working, but my only method I know that doesn’t require the window to be the foremost is PostMessage. However, it seems to always lose 0-2 characters at the beginning of the message. Is there a way I can make a check to prevent the loss? I’ve tried looping GetLastError() and re-sending it if it’s 0, but it doesn’t help any. Here’s the code I’ve gotten so far:

    public void SendPacket(string packet)
    {
        //Get window name
        IntPtr hWnd = Window.FindWindow(null, "???????????");
        //Get the first edit box handle
        IntPtr edithWnd = Window.FindWindowEx(hWnd, IntPtr.Zero, "TEdit", "");
        //Get the handle for the send button
        IntPtr buttonhWnd = Window.FindWindowEx(hWnd, IntPtr.Zero, "TButton", "SEND");
        //Iterate twice to get the edit box I need
        edithWnd = Window.FindWindowEx(hWnd, edithWnd, "TEdit", "");
        edithWnd = Window.FindWindowEx(hWnd, edithWnd, "TEdit", "");
        foreach (Char c in packet)
        {
            SendCheck(c, edithWnd);
        }
        //Press button
        TextSend.PostMessageA(buttonhWnd, 0x00F5, 0, 0);
        //Clear the edit box
        TextSend.SendMessage(edithWnd, 0x000C, IntPtr.Zero, "");
    }

    public void SendCheck(char c, IntPtr handle)
    {
        //Send the character
        TextSend.PostMessageA(handle, 0x102, c, 1);
        //If error code is 0 (failure), resend that character
        if (TextSend.GetLastError() == 0)
            SendCheck(c, handle);
        return;
    }

And here are the definitions in TextSend class:

        [DllImport("Kernel32.dll")]
        public static extern int GetLastError();
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, string s);  
  • 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-27T19:28:30+00:00Added an answer on May 27, 2026 at 7:28 pm

    The fact that you’re finding a TEdit and a TButton makes me think that the target application was written in Delphi. If so, depending on the version of Delphi it may or may not be a Unicode application. You’re calling PostMessageA instead of PostMessageW which means it’s sending a single-byte Ansi char instead of a 16-bit Unicode char from the c# application.

    Do you have source to the target application? Stuffing data in an edit box and clicking a button seems a bit fragile. If you can modify the target application there are certainly other options available than to send one character at a time.

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

Sidebar

Related Questions

I have a windows form application that will open other forms, but will only
We have an application that will be collecting data and storing it in local
I have an class which should send/receive data in packet form. This class contains
I have a form in my ASP.NET MVC 3 application that will use jquery
I am developing a web application that will display data in grid form. I
I am working on an application that will have online and offline components and
I have an application that will mainly operate in the background. I want certain
I have an application that will accept URLs from the built in web browser
I have this application that will recurse all folders in a given directory and
I have an application that requires resizing of a component that will be scaled

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.