Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Win32 (http://www.go4expert.com/forums/win32/)
-   -   big Prob WIn32 MFC API Programming vb.net (http://www.go4expert.com/forums/prob-win32-mfc-api-programming-vbnet-t929/)

theGhost_k8 24Jun2006 18:04

big Prob WIn32 MFC API Programming vb.net
 
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 vb.net
sending :: passing message to different application...
Code: VB

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 )
Code: VB

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)



All times are GMT +5.5. The time now is 18:04.