Well, at your suggestion, I changed my pinvokes to look like this.
I think the most unpleasant part of all this is that it is completely random. I have problems reproducing the problem. Some of my clients will be on 64-bit, some on 32-bit. What should I do about this? I am testing it now, and I still have the same problem. I'm losing back.
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, StringBuilder lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
Now, my passcode looks like this.
private void CreateStream(object sender, EventArgs e)
{
System.Text.StringBuilder strBuffer = new System.Text.StringBuilder();
System.Text.StringBuilder strDebug = new System.Text.StringBuilder();
int nLen = 0;
bool nUpdated = false;
try
{
this.isOpen = false;
if (ptrHandle == null)
return;
if (ptrHandle == IntPtr.Zero)
return;
nLen =
Converter.SendMessage(ptrHandle, Converter.WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero).ToInt32();
if (nLen <= 0)
return;
if (nPreviousLen != nLen)
nUpdated = true;
if (nUpdated)
{
strDebug.AppendFormat("nLen:\t{0}", nLen);
strBuffer = new System.Text.StringBuilder(null, nLen + 1);
strBuffer.Length = Converter.SendMessage(ptrHandle, Converter.WM_GETTEXT, new IntPtr(nLen)
, strBuffer).ToInt32();
strDebug.AppendFormat("\nsLen:\t{0}", strBuffer.Length);
}
}
finally
{
source = new SPECIAL.IO.TextReader(
strBuffer.ToString(), nUpdated);
source.Debugging = strDebug.ToString() ;
this.isOpen = true;
nPreviousLen = nLen;
}
}
source
share