请问能否在VB中用WM_COPYDATA把一个Type(结构)类型的数据传递给VC进程??
像这样:COPYDATASTRUCT::lpData = aTypeVal
PS:COPYDATASTRUCT::lpData 要求的是一个PVOID (void*)

解决方案 »

  1.   

    但现在最大的问题是COPYDATASTRUCT::lpData ,我要传递的是一个结构,如何取得一个结构的地址并地址传给它~???????????????????!?!?!??
      

  2.   

    varptr(your struct)
    不知道。
      

  3.   

    Getting the Address of a Variable of User-Defined Type
    An API programmer often needs to get the address of a variable of user-defined type. Consider, for example, the structure:Type utExample
       sString As String
       iInteger As Integer
    End TypeDim uEx As utExampleSuppose we want to find the address of the variable uEx. First, note that the address of a structure variable is the same as the address of its first member. Now consider the following code:Debug.Print VarPtr(uEx)
    Debug.Print VarPtr(uEx.sString)
    Debug.Print VarPtr(uEx.iInteger)
    Debug.Print
    Debug.Print rpiVarPtr(uEx)
    Debug.Print rpiVarPtr(uEx.sString)
    Debug.Print rpiVarPtr(uEx.iInteger)whose output is as follows. 1243836 
     1243836 
     1243840  1243824 
     1243820 
     1243840
     
    As you can see, VarPtr reports the address as you would expect: the address of uEx is the same as the address of uEx.aString, and the address of uEx.iInteger is 4 bytes larger, to account for the 4-byte BSTR.On the other hand, the rpiVarPtr is susceptible to BSTR-to-ABSTR translation, which occurs on the member of the structure that is a BSTR. The relationship between the first and second address in the second group may look strange until we remember that each call to rpiVarPtr produces a translation, so we cannot compare addresses from two separate calls, both of which involve translations!On the other hand, the third address is the address of the original integer member. There is no translation in the call:Debug.Print rpiVarPtr(uEx.iInteger)because there are no BSTR parameters. Thus, we can use an external function such as rpiVarPtr to compute the address of a structure provided the structure has at least one non-BSTR parameter. In this event, we get the address of one such parameter and count backwards to the beginning of the structure.MSDN索引varptr
      

  4.   

    用VARPTR()试过~~
    结果:WM_COPYDATA消息是收到了,但是~lpData的数据是不对的(杂乱无章),LOOKPublic Function NotifyReceiveMsg(EncryptType As Integer, MsgType As Integer, MsgID As Long, Optional ErrorType As Integer = 0) As Long
        If g_hwndParent <> 0 Then
            Dim rm As TReceiveMsg
            Dim cs As COPYDATASTRUCT
            With rm
                .EncryptType = EncryptType
                .MsgType = MsgType
                .MsgID = MsgID
                .MsgType = ErrorType
            End With
            With cs
                .dwData = NT_RECEIVE_MSG
                .cbData = DL_RECEIVE_MSG
                .lpdata = VarPtr(rm)
    '            With .lpdata
    '                .EncryptType = EncryptType
    '                .MsgType = MsgType
    '                .MsgID = MsgID
    '                .MsgType = ErrorType
    '            End With
            End With
            NotifyReceiveMsg = CopyDataSendMessage(g_hwndParent, WM_COPYDATA, g_hwndSelf, cs)
        Else
            NotifyReceiveMsg = -1
        End If
    End Function
    当我这样调用函数的时候:NotifyReceiveMsg 3, 1, 12345, 0
    接收程序得到的结果是:
    lpData.EncryptType == -448
    lpData.MsgType == 18
    lpData.MsgID == 2082894080
    lpData.ErrorType == 11161郁闷啊
      

  5.   

    哈~~~~~~~~~~~~~
    用VARPTR()解决了~~~~~~~~~~
    是我的错!!!!
    万分感谢~~~~~~~请问如何给分????????????