Groups | Blog | Home
all groups > dotnet interop > march 2007 >

dotnet interop : Sending chars between VB6 and C#.NET



Mattias Sjögren
3/31/2007 12:00:00 AM
[quoted text, click to view]

What does the SendMessage code on the VB6 side look like?

To pass data buffers between processes, you typically have to use the
WM_COPYDATA message.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Miro
3/31/2007 12:06:02 AM
Hello!

I'm using windows messages and the LParam parameter to send chars as ASCII
numbers from VB6 to C#. How can I retrieve the right int value from the
IntPtr in .NET?

My code:

protected override void WndProc(ref Message m)
{
if (m.Msg == VB6_TO_CSHARP_MessageId.ToInt32())
{
int test = m.LParam.ToInt32();
String test2 = m.GetLParam(typeof(int)).ToString();
...
}
}

test is a long number (for instance 1234621) and test2 is usually "0". I've
Miro
3/31/2007 7:28:02 AM
The code is as follows. Is it enough to change the MessageID to WM_COPYDATA
or do I have to create and send a COPYDATASTRUCT? I f you have some code I
would be grateful.

Public Function SendMessageToCSharp(theChar As Integer)
Dim hwndTarget As Long
Dim MessageId As Long

If WindowMessagingInitialised = False Then
InitWindowMessaging
End If

'Get TargetWindow handle from global Window Name
hwndTarget = CSharp_WindowHandle

'Get MessageId from API call to RegisterMessage
MessageId = VB6_TO_CSharp_MessageId

'If Window target exists, then SendMessage to target
If hwndTarget <> 0 Then
Call PostMessage(hwndTarget, MessageId, o, theChar)
End If
End Function



[quoted text, click to view]
AddThis Social Bookmark Button