Passing a string from VB6 to VB.NET
Posted on 2004-08-04
I have a program written in vb6 that needs to send a string to a program written in VB.NET. I'm tring to use window messages to do this. So in the VB6 program I'd have:
SendMessage hwnd, WM_COMMAND, MessageType, "The Message"
and in vb.net I override the WndProc to catch WM_COMMAND messages and then do something with the string:
Of course, that doesn't work. LParam is an IntPtr, not a string. So I tried this:
which returned junk (I tried PtrToStringUni and PtrToStringAuto with the same result). I also tried changing the SendMessage declaration. I origionally used
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
and I've tried changing the lParam declaration to be 'ByRef lParam as String'. I've also tried making the lParam declaration 'ByVal lParam as Long', and passing the string as 'StrPtr("The Message")'.
Incidentally, I am receiving the MessageType number correctly, and can switch on its value, and I can see that m.lParam.toInt32() is changing each time I get a message.
How do I get the string to go through correcly?