SendMessage API with strings as parameters

T

Tim Mulholland

I think the problem i'm having is a little bigger than this, but i hope the
answer to this question will send me down the right path.

I'm calling the SendMessage API function from C#. I've got it so i cna send
the messages fine normally using this declaration:

[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern uint SendMessage(IntPtr hWnd, int Msg, IntPtr wParam,
IntPtr lParam);

but i have a call that i need to make now that actually uses the wParam
value. (i had just been passing IntPtr.Zero in all other working cases).

this function requires wParam to be a string that specifies what should go
on when that message is received.
I've been looking through all kinds of information and can't figure out what
i'm supposed to do. Marshaling seems like the right direction, but you can't
Marshal a string without knowing the length at compiletime right? (so you
can set the [MarshalAs(UnmanagedType.ByValTStr, SizeConst=90)] type of
attributes and all that?)

So what are my options here?

Thanks in advance,

-Tim
 
M

Mattias Sjögren

Tim,
I've been looking through all kinds of information and can't figure out what
i'm supposed to do.

Add another overload where wParam is typed as string

[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern uint SendMessage(IntPtr hWnd, int Msg, string
wParam, IntPtr lParam);



Mattias
 
T

Tim Mulholland

that doesn't work.
the string comes through on the other end as gibberish.
i reposted another thread about this on the 29th at 4:04pm if you want to
see more information...

Mattias Sjögren said:
Tim,
I've been looking through all kinds of information and can't figure out what
i'm supposed to do.

Add another overload where wParam is typed as string

[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern uint SendMessage(IntPtr hWnd, int Msg, string
wParam, IntPtr lParam);



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top