c的dll里的部分代码是:
///////////////////////////
char str[100]="dll发来的消息是: ...";
SendMessage(m_hWnd,12,*str,0);//m_hWnd是vb窗口的代号
//////////////////////////////////vb的窗口处理函数是:
'''''''''''''''''''''''''''''
Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  dim str1 as string*100
  If uMsg = 12 Then
      MsgBox "收到dll字符串消息,字符串是:(?????)"
   End If
  WndProc = CallWindowProc(GetProp(hWnd, OLDWNDPROC), hWnd, uMsg, wParam, lParam)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''
vb如何将vc里的str字符串提取到vb代码的"字符串是:(?????)"或str1里????

解决方案 »

  1.   

    c的dll里的部分代应该是: 
    /////////////////////////// 
    char str[100]="dll发来的消息是: ..."; 
    SendMessage(m_hWnd,12,strlen(str),*str);//m_hWnd是vb窗口的代号 
    ////////////////////////////////// 
    第一次发错了!
      

  2.   

    用CopyMemory函数(声明你自己找吧,我这里没装VB,查不了)
    Dim byteVal() As Byte
    Dim str As StringRedim byteVal(1 To wParam) As Byte '看你从DLL发出的消息,wParam参数应该是字串字节大小
    CopyMemory byteVal(1), ByVal lParam, wParam
    str = StrConv(byteVal, vbFormUnicode)
    'str = StrConv(byteVal, vbUnicode)
    '上面两个字符转换随便试一个,我这里没得调试
      

  3.   

    12的消息时wm_quit,,,,
      

  4.   

    2楼的有点错误,对方没有传递字符串长度过来,所以应该是这样
    Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long 
        dim a(100-1) as byte, lLen as long, str as string
        If uMsg = 12 Then 
            copymemory a(0), byval wParam, 100
            lLen = instrB(1, a, chr(0)) 'C 标准字符串以 \0 结束
             if lLen <> 0 then '如果发送的字符串没有用 \0 结束(因此没有用lstrcpy而是用copymemory),就认为字符串长 100,否则截短
                 redim preserve a(lLen-1)
            end if
            str = strconv(a, vbUnicode)
            MsgBox "收到dll字符串消息,字符串是:(" & str & ")" 
       End If 
       WndProc = CallWindowProc(GetProp(hWnd, OLDWNDPROC), hWnd, uMsg, wParam, lParam) 
    End Function 
      

  5.   

    你dll和VB程序是在一个进程里么
      

  6.   

    你dll和VB程序是在一个进程里么
      

  7.   

    回:supergreenbean
    是在一个进程里的!!
      

  8.   

    那么VC里面改成
    SendMessage(m_hWnd,12,(WPARAM)str,0);VB里面的代码可以用Tiger_Zhao在4楼写的代码
    不过,建议你直接回调VB的过程,从而直接传入字符串
      

  9.   

    c代码我也该成"SendMessage(m_hWnd,12,(WPARAM)str,0); "回:VB老鸟
    连接错误啊!
    "ReDim Preserve a(lLen - 1)"错误!提示是:数组维数已经定义!
    我把"dim a(100-1) as byte"改成"dim a() as byte",!错误!提示是:"实时错误:'9'下标越界!"
    怎么办啊?这是什么错误?
      

  10.   

        dim a() as byte
        redim a(lLen-1)
      

  11.   

     dim a() as byte 
    lLen=100
    redim a(lLen-1) 
      

  12.   

    我改了:
    vc:
    ///////////////////
    SendMessage(m_hWnd,12,(WPARAM)str,(LPARAM)strlen(str));
    //////////////////////
    vb:
    ''''''''''''''''''''''''''''''''''''''''''''''''
    Dim a() As Byte, i As Long, str As String
        If uMsg = 12 Then
            ReDim a(lParam - 1)
            CopyMemory a(0), ByVal wParam, lParam
            str = StrConv(a, vbUnicode)
            MsgBox "收到dll字符串消息,字符串是:(" & str & ")"
       End If
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    程序没有执行:MsgBox "收到dll字符串消息,字符串是:(" & str & ")"
      

  13.   

    我又改了:
    vc: 
    /////////////////// 
    SendMessage(m_hWnd,12,(WPARAM)str,0);
    ////////////////////// 
    vb: 
    Dim a(100) As Byte, i As Long, str As String
        If 12 = uMsg Then
         '  MsgBox "!!!!"
       '     ReDim a(wParam - 1)
            CopyMemory a(0), ByVal wParam, 100
            str = a
      '      str = StrConv(a, vbUnicode)
            Form1.Text1 = str
            MsgBox "收到dll字符串消息,字符串是:(" & str & ")"
       End If
    结果str全是:"?????"
      

  14.   

    最好不用str做为变量名,这是VB的保留字,是一个函数的名
    试:str1=strconv(a,vbfromunicode)
      

  15.   

    我最后测试通过了:
    vb代码是:
    '''''''''''''''''''''''''
    Dim a() As Byte, i As Long, str As String
        If 12 = uMsg Then
           ReDim a(wParam - 1)
           CopyMemory a(0), ByVal lParam, wParam
           str = StrConv(a, vbUnicode)
            Form1.Text1 = str
            MsgBox "收到dll字符串消息,字符串是:(" & str + ")"
       End If
    ''''''''''''''''''''''''''''''''''''''''''''''''''''
    vc代码是:
    ///////////////
    SendMessage(m_hWnd,12,strlen(str),(LPARAM)&(*str));//m_hWnd是vb窗口的代号
    ////////////////////////
    不知道我以上代码在:dll和VB程序不是同一个进程的情况下是否可以通过?