Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling SendMessage (P/Invoke) keeps crashing
    primarykey
    data
    text
    <p>I am having to write an application that communicates with a third-party program (<a href="http://en.wikipedia.org/wiki/AOL" rel="nofollow noreferrer">AOL</a>, I'm sorry. :()</p> <p>Doing a lot of research I found some ways to do this with <a href="http://en.wikipedia.org/wiki/Platform_Invocation_Services" rel="nofollow noreferrer">P/Invoke</a>, and for the most part it <em>works</em> okay, but it crashes upon subsequent trials, specifically with <code>SendMessage</code>. I'm outlining the crashing code below.</p> <p>All of this was ported to <a href="http://en.wikipedia.org/wiki/.NET_Framework" rel="nofollow noreferrer">.NET</a> 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.</p> <pre><code>[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 &amp;&amp; aollist != IntPtr.Zero &amp;&amp; aolicon != IntPtr.Zero &amp;&amp; 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 &amp;&amp; aollist != IntPtr.Zero &amp;&amp; aolicon != IntPtr.Zero &amp;&amp; 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); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload