I have the following function:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, SPoint lParam);
It keeps complaining about Pinvoke stack imbalance when the following code executes:
SendMessage(EventRichTextBox.Handle, EM_GETSCROLLPOS, 0, OldScrollPoint);
What can cause that issue?
this is my SPoint
private struct SPoint
{
public Int32 x;
public Int32 y;
}
and
SPoint OldScrollPoint = default(SPoint);
Can’t say for sure, but one obvious possibility is that you are on a 64 bit machine and
intis the wrong type forwParam. It needs to be a 64 bit value in a 64 bit process.We also have no idea how you have declared
SPoint. You are meant to pass a pointer to aPOINTstruct. It doesn’t look as though you have done that.The correct signature is:
Your edit clarifies that
SPointis a struct. This then is clearly wrong. You could simply pass theSPointas anoutparameter. That would be the simplest solution.If you wanted a more general
SendMessagesignature then you should useIntPtras I stated above and useMarshal.StructureToPtr.