Hello everyone,
I have two apps ,one in vb and another in vb.net .Now I'm trying to send messages from one another.I'm able to detect the receipt of messages both ways.I'm also able to send a structure of the form
VB Code:
Private Type MyStructure dwData As Long cbData As Long lpData As Long End Type
from vb6 to vb.net but when i attempt to send a structure from vb.net to vb6,it is not able to convert the data back to its original structure.
The logic i used to convert is simple
On the sender side:
VB Code:
Private Type MyStructure dwData As Long cbData As Long lpData As Long End Type Private Const WM_COPYDATA = &H4A Public Function SendMessageToVBNET() Dim hwndTarget As Long Dim MessageId, i As Long Dim a As String Dim cds As MyStructure Dim ThWnd As Long Dim buf(1 To 255) As Byte ThWnd = FindWindow(vbNullString, "VB.NET Main Form") a$ = "I'm from VB6" Call CopyMemory(buf(1), ByVal a$, Len(a$)) cds.dwData = 3 cds.cbData = Len(a$) + 1 cds.lpData = VarPtr(buf(1)) 'Converting a string 'a' to long so we can send it with the message If WindowMessagingInitialised = False Then InitWindowMessaging 'this starts the subclassing End If hwndTarget = VBNET_WindowHandle 'this gets the handle of target MessageId = VB6_TO_VBNET_MessageId 'this is an indicator for the target that message is from vb6 If hwndTarget <> 0 Then i = SendMessage(hwndTarget, WM_COPYDATA, MainForm.hwnd, cds) End If End Function
On the receiver side:
Using Marshalling to convert pointer to structure
VB Code:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Dim Mypoint As MyStructure If m.Msg = WM_COPYDATA Then Mypoint = CType(Marshal.PtrToStructure(m.LParam, GetType(MyStructure)), MyStructure) MsgBox("Value of X> " & Mypoint.x & " <Value of Y> " & Mypoint.y & " <Value of XY> " & Mypoint.xy & " <-") End If MyBase.WndProc(m) End Sub
I have attached two zip files.
1.vb-vb.zip has two projects ,one sender and one receiver and they are working as expected.
2.vb-vbnet.zip has two projects, one in vb6 and another in vb.net using the same logic as above.




Reply With Quote