Results 1 to 3 of 3

Thread: [RESOLVED] VB6 and VB.NET Interprocess Comm.

Threaded View

  1. #1

    Thread Starter
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    Resolved [RESOLVED] VB6 and VB.NET Interprocess Comm.

    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:
    1. Private Type MyStructure
    2.   dwData As Long
    3.   cbData As Long
    4.   lpData As Long
    5. 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:
    1. Private Type MyStructure
    2.               dwData As Long
    3.               cbData As Long
    4.               lpData As Long
    5.       End Type
    6.  
    7.       Private Const WM_COPYDATA = &H4A
    8.  
    9.   Public Function SendMessageToVBNET()
    10.     Dim hwndTarget As Long
    11.     Dim MessageId, i As Long
    12.     Dim a As String
    13.     Dim cds As MyStructure
    14.     Dim ThWnd As Long
    15.     Dim buf(1 To 255) As Byte
    16.  
    17.     ThWnd = FindWindow(vbNullString, "VB.NET Main Form")
    18.     a$ = "I'm from VB6"
    19.     Call CopyMemory(buf(1), ByVal a$, Len(a$))
    20.     cds.dwData = 3
    21.     cds.cbData = Len(a$) + 1
    22.     cds.lpData = VarPtr(buf(1))   'Converting a string 'a' to long so we can send it with the message
    23.  
    24.     If WindowMessagingInitialised = False Then
    25.       InitWindowMessaging                           'this starts the subclassing
    26.     End If
    27.  
    28.     hwndTarget = VBNET_WindowHandle         'this gets the handle of target
    29.  
    30.     MessageId = VB6_TO_VBNET_MessageId    'this is an indicator for the target that message is from vb6
    31.  
    32.     If hwndTarget <> 0 Then
    33.                 i = SendMessage(hwndTarget, WM_COPYDATA, MainForm.hwnd, cds)
    34.  
    35.     End If
    36.   End Function

    On the receiver side:
    Using Marshalling to convert pointer to structure

    VB Code:
    1. Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    2.         Dim Mypoint As MyStructure
    3.  
    4.  
    5.         If m.Msg = WM_COPYDATA Then
    6.             Mypoint = CType(Marshal.PtrToStructure(m.LParam, GetType(MyStructure)), MyStructure)
    7.             MsgBox("Value of X> " & Mypoint.x & " <Value of Y> " & Mypoint.y & " <Value of XY> " & Mypoint.xy & " <-")
    8.  
    9.  
    10.         End If
    11.         MyBase.WndProc(m)
    12.  
    13.     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.
    Last edited by litlewiki; Apr 13th, 2007 at 02:02 PM.
    __________________
    ________________0îîî___
    ___îîî0________(___)____
    __(___)_________) _/_____
    ___\_ (_________(_/______
    ____\_)_________________

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width