views:

24

answers:

3

I'm having a heck of a time figuring this out, the tutorials I found on the web are not complete or are for VB 6.0 (obsolete in some cases). On the C++ side I have the following ::

..... hwndExternalApplication = FindWindow(NULL, L"Dromocast Client"); SendMessage(hwndExternalApplication, WM_SETTEXT, NULL, (LPARAM)"Hello"); .....

"Dromocast Client" is my visual basic application, and I checked to make sure it's not NULL. In fact I get made sure I'm getting some data on the VB side. On my Visual Basic side I have the following ::

Protected Overrides Sub WndProc(ByRef m As Message)
    Select Case (m.Msg)
        Case WM_SETTEXT
            Dim strTemp As String
            strTemp = System.Runtime.InteropServices.Marshal.PtrToStringUni(m.LParam)
            MessageBox.Show("GOT THE MESSAGE, SETTING LOCAL VARIABLE")
    End Select

    MyBase.WndProc(m)
End Sub

When I send the data over it's garbage, meaning strTemp comes out as all these chinese characters, and my title bar on the visual basic program gets garbled with a bunch of chinese characters as well. My guess is my "SendMessage" is written wrong, or I'm doing something silly, but I have no idea what. I'm not a windows programmer so I'm kinda trying to figure this stuff out by googling....any help would be greatly appreciated.

A: 

Try to change (LPARAM)"Hello" to (LPARAM)L"Hello" . I think .net expects string to be widechar.

Andrey
THANK YOU SO MUCH! I'm not sure what I was doing wrong originally, but it wasn't working. Cleaned up my code a bit,removed dll's function calls I wasn't using and it worked like a charm.
Fernando
A: 

Yeah I tried that, still didn't work. I'm going to create a stand alone program and see if I can find out what's wrong that way. Does it matter that the C++ code is a MFC DLL?

A: 

Your C string isn't a Unicode string, it's an ANSI string. Try using PtrToStringANSI instead of PtrToStringUnicode

MarkJ