C #: Marching "pointer to an array of int" from SendMessage () lParam

I am trying to subclass an unmanaged status window from my managed COM server using a class inherited from NativeWindow, and I am running into the wall trying to figure out how to properly marshal the contents of lParam.

http://msdn.microsoft.com/en-us/library/bb760757%28VS.85%29.aspx says that the contents of this lParam are of type (LPARAM)(LPINT) aWidthsand that the contents of this variable is actually a "pointer to an integer array."

I can’t figure out how to do it right. The goal is to read lParam, add our value to the array, and then send a new message through base.wndProc(ref m).

It would be nice if I could just int[] array = (int[])m.*lParamor somesuch, but life is not so simple (and I can not use unsafe code). I clumsily tried to get the marshaller to give me something through Marshal.PtrToStructure(), but I knew that it was doomed from the very beginning, since the C-array is not a structure, and the structure that I tried to make, obviously, cannot be softened.

We now resolve the original call, and then make additional WinAPI calls to get the array, format it, and resend it before the status bar can redraw. This works well, but not enough.

Any ideas?

Thank!

Tom

PS- I had a lot of problems with grokking, as lParams are used in C #, the documentation is pretty confusing: - /

+1
source share
1

"dtb", - SO > .

LPARAM, , . , , :

int[] parts = new int[]{ 1, 2, 3, 4 };
int nParts = parts.Length;
IntPtr pointer = Marshal.AllocHGlobal(nParts * Marshal.SizeOf(typeof(int)));
for (int i = 0; i < nParts; i++) {
    Marshal.WriteInt32(pointer, i * Marshal.SizeOf(typeof(int), parts[i]));
}
// Call SendMessage with WPARAM = nParts and LPARAM = Pointer
Marshal.FreeHGlobal(pointer);
+2

All Articles