SendMessage API w/ strings

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I just realized i had been posting under a managed newsgroup account that had
expired. hopefully this one works better and gets me a response from
Microsoft..

I have an MFC app that i'm trying to send messages to using the SendMessage
API through a C# application

Here is the signature and the first line of code for the function that
receives this message in the MFC application:

LRESULT CMainFrame::OnLoadVidAnaly( WPARAM wParam, LPARAM lParam )
{
CString strConfig = (LPCTSTR) wParam;
...
return 1;
}

I've tried all kinds of ways of declaring the extern function to make this
call... they all result in different (and all incorrect) results.
For the first parameter i've tried using a StringBuilder, a string or an
IntPtr. Using StringBuilder, i end up with strConfig being = "". Using a
string, i end up with strConfig being = a bunch of garbage. If i use an
IntPtr and use some of the marshalling functions (StringToBSTR,
StringToHGlobalAuto, etc) that first line of the function throws an
exception.

Can you help me figure out whats going on and how to appropriately call this
SendMessage call?

Thanks in advance,

-Tim
 
Tim,

Is the MFC code compiled as ANSI or Unicode?

Is it running in the same process as the C# code sending the message,
or in a separate process?



Mattias
 
the character set of the project is set to "Use Multi-Byte Character Set"
though i'm not sure what that means or if it answers your question..

The MFC code is currently running in a different process, though it may
eventually be running in the same process. Does this make a difference? For
SendMessage, i didn't think that it did.

-Tim
 
Tim,
the character set of the project is set to "Use Multi-Byte Character Set"
though i'm not sure what that means or if it answers your question..

Yes it does, thanks.

The MFC code is currently running in a different process, though it may
eventually be running in the same process. Does this make a difference? For
SendMessage, i didn't think that it did.

Yes it makes a big difference in this case. For custom window
messages, Windows doesn't know what the message parameters mean. So it
can't marshal pointer types across process bounaries (how would it
know how much data to copy), so you can't pass around strings like
that. You either have to stay in proc, or use a message such as
WM_COPYDATA that lets you specify how much data to send.



Mattias
 
Back
Top