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

  • Home
  • SEARCH
  • 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 578203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:14:07+00:00 2026-05-13T14:14:07+00:00

I am having to write an application that communicates with a third-party program (

  • 0

I am having to write an application that communicates with a third-party program (AOL, I’m sorry. :()

Doing a lot of research I found some ways to do this with P/Invoke, and for the most part it works okay, but it crashes upon subsequent trials, specifically with SendMessage. I’m outlining the crashing code below.

All of this was ported to .NET from old, old Visual Basic files. It’s archaic as it can be, and I understand if it’s not doable – I was just hoping there was a better way than Visual Basic 4.0 to get this done.

[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseHandle(IntPtr hObject);

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent,
                                         IntPtr hwndChildAfter,
                                         string lpszClass,
                                         string lpszWindow);

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

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(HandleRef hWnd,
                                        UInt32 Msg,
                                        IntPtr wParam,
                                        IntPtr lParam);

[DllImport("user32.dll", EntryPoint="SendMessageW")]
public static extern IntPtr SendMessageByString(HandleRef hWnd,
                                                UInt32 Msg,
                                                IntPtr wParam,
                                                StringBuilder lParam);

[DllImport("user32.dll", CharSet = CharSet.Unicode , EntryPoint = "SendMessageW")]
public static extern IntPtr SendMessageByString(HandleRef hWnd,
                                                UInt32 Msg,
                                                IntPtr wParam,
                                                String lParam);

public IntPtr FindClientWindow()
{
    IntPtr aol = IntPtr.Zero;
    IntPtr mdi = IntPtr.Zero;
    IntPtr child = IntPtr.Zero;
    IntPtr rich = IntPtr.Zero;
    IntPtr aollist = IntPtr.Zero;
    IntPtr aolicon = IntPtr.Zero;
    IntPtr aolstatic = IntPtr.Zero;

    aol = Invoke.FindWindow("AOL Frame25", null);
    mdi = Invoke.FindWindowEx(aol, IntPtr.Zero, "MDIClient", null);
    child = Invoke.FindWindowEx(mdi, IntPtr.Zero, "AOL Child", null);
    rich = Invoke.FindWindowEx(child, IntPtr.Zero, "RICHCNTL", null);
    aollist = Invoke.FindWindowEx(child, IntPtr.Zero, "_AOL_Listbox", null);
    aolicon = Invoke.FindWindowEx(child, IntPtr.Zero, "_AOL_Icon", null);
    aolstatic = Invoke.FindWindowEx(child, IntPtr.Zero, "_AOL_Static", null);

    if (rich != IntPtr.Zero &&
        aollist != IntPtr.Zero &&
        aolicon != IntPtr.Zero &&
        aolstatic != IntPtr.Zero)

        return child;
    do
    {
        child = Invoke.FindWindowEx(mdi, child, "AOL Child", null);
        rich = Invoke.FindWindowEx(child, IntPtr.Zero, "RICHCNTL", null);
        aollist = Invoke.FindWindowEx(child, IntPtr.Zero, "_AOL_Listbox", null);
        aolicon = Invoke.FindWindowEx(child, IntPtr.Zero, "_AOL_Icon", null);
        aolstatic = Invoke.FindWindowEx(child, IntPtr.Zero, "_AOL_Static", null);

        if (rich != IntPtr.Zero &&
            aollist != IntPtr.Zero &&
            aolicon != IntPtr.Zero &&
            aolstatic != IntPtr.Zero)

            return child;
    }
    while (child != IntPtr.Zero)
        ;

    return child;
}

IntPtr room = IntPtr.Zero;
IntPtr child = IntPtr.Zero;
IntPtr length = IntPtr.Zero;
IntPtr roomHandle = IntPtr.Zero;

child = FindClientWindow();
room = FindChildByClass(child, "RICHCNTLREADONLY");

HandleRef n = new HandleRef(IntPtr.Zero, room);

length = SendMessage(n, 0x000E, IntPtr.Zero, IntPtr.Zero);

// This is the line that keeps crashing on me.
SendMessageByString(n, 0x000D, new IntPtr( length.ToInt32() + 1 ), str);

public IntPtr FindChildByClass(IntPtr parent, string child)
{
    return Invoke.FindWindowEx(parent, IntPtr.Zero, child, null);
}
  • 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-13T14:14:07+00:00Added an answer on May 13, 2026 at 2:14 pm

    You are using the Wide byte SendMessage..ie for Wide Characters, have you tried the normal Sendmessage..
    public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);

    I also notice it’s like as if you are trying to change the value based on the handle of the richtextbox’s control hence the looking around for the AOL’s client window in another process…is that correct?

    That could be the source of the problem, directly modifying a control that belongs to a window that is not yours (your program is managed, modifying a unmanaged process’s window)…that could explain why it crashed. Can you clarify what is the hex constants for?

    Edit: When you use the WM_GETTEXTLENGTH and WM_GETTEXT, they are part of the Windows Messages to retrieve the text length and the actual text from the control. If you look here and see what pinvoke.net has to say about them..When you issue a ‘SendMessage’, with WM_GETTEXTLENGTH and WM_GETTEXT, you are telling Windows – ‘Hey, get me the length of the text in that associated handle which I’ve given you in the parameter n. Just occurred to me, worth trying out…I would get rid of those SendMessage pinvokes and use just this one..

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, StringBuilder lParam);
    //If you use '[Out] StringBuilder', initialize the string builder with proper length first.
    
    
    child = FindClientWindow();
    room = FindChildByClass(child, "RICHCNTLREADONLY");
    
    length = SendMessage(n, 0x000E, IntPtr.Zero, IntPtr.Zero);
    
    StringBuilder sbBuf = new StringBuilder(length);
    
    SendMessageByString(room, 0x000D, new IntPtr( length.ToInt32() + 1 ), out sbBuf); // this is the line that keeps crashing on me.
    

    Try that and get back here … 🙂

    Hope this helps,
    Best regards,
    Tom.

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

Sidebar

Ask A Question

Stats

  • Questions 307k
  • Answers 307k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could set up public key authentication over SSH to… May 13, 2026 at 9:24 pm
  • Editorial Team
    Editorial Team added an answer Do it in the Session_Start method in your Global.asax like… May 13, 2026 at 9:24 pm
  • Editorial Team
    Editorial Team added an answer Apparently, I was unaware of this: the URL fragment is… May 13, 2026 at 9:24 pm

Related Questions

I'm about to start a project that requires XML messages to be sent between
I wrote a device controller (rs232) and it is being used successfully, however users
Say I have an application that used an ORM (I am thinking of nHibernate
I am a long time Microsoft developer and I am new to iPhone development
I am trying to write an interface between RSPEC (ruby flavoured BDD) and a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.