big Prob WIn32 MFC API Programming

Discussion in 'Win32' started by theGhost_k8, Jun 24, 2006.

  1. theGhost_k8

    theGhost_k8 New Member

    Jun 24, 2006
    Likes Received:
    Trophy Points:
    what i'm trying to do is go pass a structure to different application usin WM_COPYDATA and sendmessage... may be the problem lies in marshalling .. please have a look and help me.......
    solve the error.. i'm not able to recv data using wm_copydata by RPC
    sending :: passing message to different application...
           Dim data As CopyData
            Dim message As String = "this is to be sent"
            Dim obj As struct
            obj.s = "trialDAMN"
            data.lpData = Marshal.AllocHGlobal(Marshal.SizeOf(obj))
            data.dwData = obj
            Marshal.StructureToPtr(obj, data.lpData, True)
            data.cbData = Marshal.SizeOf(obj)
            data.lpData = Marshal.StringToHGlobalAuto(message)
            Dim hwndTarget As IntPtr
            Dim MessageId As IntPtr
            hwndTarget = Me.GET_HANDLE_TWO
            MessageId = ONE_TO_TWO_MESSAGEID()
            ' send the data
            SendMessage(hwndTarget, WM_COPYDATA, Me.Handle, data)
    receiving and handling message and data.... using wndproc( dfsdfasdf )
       Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            Select Case m.Msg
                Case WM_COPYDATA
                    Dim data As CopyData
                    Dim message As String
                    Dim obj As struct
                    obj = CType(m.GetLParam(GetType(CopyData)), CopyData).dwData
                    MsgBox("lets c--" & obj.s)
                    data = CType(m.GetLParam(GetType(CopyData)), CopyData)
                    MsgBox("size of --- " & Marshal.SizeOf(data).ToString)
                    obj = CType(m.GetLParam(GetType(struct)), struct)
                    obj = Marshal.PtrToStructure(CType(m.GetLParam(GetType(CopyData)), CopyData).lpData, GetType(struct))
                    MsgBox("object's data is --- " & obj.s)
                    MsgBox("Dwdata contents are : " & data.dwData.s.ToString)
                    obj = data.dwData  ' CType(data.dwData, struct)
                    MsgBox("Object's data obtained 2nd method -- " & obj.s)

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice