beijiquan1982
beijiquan1982
采纳率0%
2015-03-02 03:41 阅读 2.1k

vb与c#之间通信,VB不能正常接收数据

两个程序之间用WM_COPYDATA方法传递数据,现在VB向c#发送数据,c#可以正常接收(不管VB发送的数据有多长);c#向VB发送的数据长度小于50,VB能正常接收。问题是c#向VB发送的数据长度大于50的话,VB只能接收前50个,不知道问题出现在哪,请各位高手帮忙看一下,也可qq联系我45262121,另源程序代码附上 http://ask.csdn.net/mentors#图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • danielinbiti danielinbiti 2015-03-02 06:10

    最好把vb接收部分的代码贴一下,把API和结构体的声明类型贴出来。

    点赞 评论 复制链接分享
  • beijiquan1982 beijiquan1982 2015-03-02 07:58

    VB接收部分的代码:
    Function WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim l As Long, sData As String
    If Msg = WM_COPYDATA Then
    pRecData = VarPtr(DatrStruct)
    CopyMemory DatrStruct, ByVal lParam, LenB(DatrStruct)
    Form1.Text3 = DatrStruct.lpData
    Else
    WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam)
    End If
    End Function
    VB的api和结构体声明类型如下:
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long

    Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

    Public Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    Public Declare Function postMessage Lib "user32" Alias "PostMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
    (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

    Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" _
    (ByVal hWnd As Long) As Long

    Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
    (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

    Public Declare Function EnumWindows Lib "user32" _
    (ByVal lpEnumFunc As Long, ByVal lParam As Any) As Long

    Public Declare Function EnumChildWindows Lib "user32" _
    (ByVal hwndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Any) As Long

    Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long) As Long

    Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (pDst As Any, pSrc As Any, ByVal ByteLen As Long)

    Public Const GWL_WNDPROC = (-4)
    Public Const WM_USER = &H400
    Public Const WM_GETTEXTLENGTH = &HE
    Public Const WM_SETTEXT = &HC 'Setting text of child window
    Public Const WM_GETTEXT = &HD 'Getting text of child window
    Public Const WM_COPYDATA As Long = &H4A
    Public Const IPC_PLAYFILE = 200
    Public frmText As String, frmHwnd As Long
    Public CtlText As String '控件文字
    Public Txthwnd As Long '要用SendMessage发送消息的控件的句柄
    Public pRecData As Long

    Public sData As String
    Public prevWndProc As Long
    Public Type COPYDATASTRUCT
    dwData As Long '结构长度,传lenb(DatrStruct)
    cbData As Long '后面指针所指内容的长度,传lenb([字符串])
    lpData As String '声明为一个String,然后直接赋值为字符串变量就行.
    End Type
    Public DatrStruct As COPYDATASTRUCT
    Public DataStruct As COPYDATASTRUCT

    点赞 评论 复制链接分享

相关推荐