How to define SendMessage once and at each call marshal the arguments

  • Thread starter Thread starter SamSpade
  • Start date Start date
S

SamSpade

I have a library which defines things like: EM_SETPARAFORMAT

Then I define an overload of SendMessage so that I can use it.

By now I have quite a few of these overloads.

Isn't there some way I can define SendMessage once and at each call marshal
the arguments?



Thanks in advance
 
SamSpade,

Yes, you can. You can declare SendMessage as follows:

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int SendMessage(
IntPtr hWnd
[MarshalAs(UnmanagedType.U4)] int Msg,
IntPtr wParam,
IntPtr lParam);

Then, all you have to do is marshal the structures, usually through a
call to the static StructToPtr method on the Marshal class (as well as any
calls to allocate and free memory).

Hope this helps.
 
If when I read the doc on StructToPtr it's understandable I think you've
helped a lot.
Thanks

Nicholas Paldino said:
SamSpade,

Yes, you can. You can declare SendMessage as follows:

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int SendMessage(
IntPtr hWnd
[MarshalAs(UnmanagedType.U4)] int Msg,
IntPtr wParam,
IntPtr lParam);

Then, all you have to do is marshal the structures, usually through a
call to the static StructToPtr method on the Marshal class (as well as any
calls to allocate and free memory).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

SamSpade said:
I have a library which defines things like: EM_SETPARAFORMAT

Then I define an overload of SendMessage so that I can use it.

By now I have quite a few of these overloads.

Isn't there some way I can define SendMessage once and at each call marshal
the arguments?



Thanks in advance
 
Back
Top