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

问题描述

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

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

解决方案

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

解决方案二:

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

时间: 2024-09-24 01:00:55

代码-vb与c#之间通信,VB不能正常接收数据的相关文章

串口通信-android蓝牙串口接收数据

问题描述 android蓝牙串口接收数据 最近在做android手机蓝牙和单片机通信,一直被接收数据完整性这个问题困扰. 为了使一次通信的包保持完整,我就构思了发送12位的包,包头(1)+数据(8)+校验(2)+包尾(1),校验为求和校验.单片机发送数据的函数如下 void SendString(uchar *dat) //发送12位的包 包头(1)+数据(8)+校验(2)+包尾(1) { uchar i,j; uint check=0; //求和校验 SendChar(0x01); //0x0

串口通信-串口程序发送接收数据问题 (没有据传输)

问题描述 串口程序发送接收数据问题 (没有据传输) //接收数据 void ReceiveChar() { BOOL istrue; DWORD de = 0; char buffer[MAX] = { 0 }; DWORD data; BOOL f; DWORD doe; COMSTAT coms; BOOL m; OVERLAPPED over; /*********串口事件的设置***************/ istrue = SetCommMask(hComm, EV_RXCHAR |

VB多个输入框之间互相获取对方输入的数据

问题描述 VB多个输入框之间互相获取对方输入的数据 VB多个输入框之间互相获取对方输入的数据,怎么判断对方正在输入数据,并且显示"正在输入"的提示? 解决方案 两个输入框如果在一个窗口,直接在change事件里面处理就行了,否则可以使用窗体子类化拦截消息. 解决方案二: 可以使用keypress函数

VB应用:在TEXTBOX中使用逗号区分数据

数据 ---------VB应用:在TEXTBOX中使用逗号区分数据------------ 主要作用是在查询数据库时,要求同一字段的多条件的查询,SQL语句的生成,下面代码是利用一个TextAfter的数组存放用逗号分隔开的数据. Dim intTextLen, i, k As Integer Dim TextBefore, TextAfter(100) As String intTextLen = Len(TextBox1.Text) k = 1 TextBefore = TextBox1.

求一VB.NET通过modbus发送接收数据的例程

问题描述 因为没接触过vb.net,所以想找个完整的例子程序.网上查的都是用VB的mscomm这个控件,而visualstudio2005下的vb.net是serialport,许多属性都随之改变.希望有个这方面的高手能给个完整的modbus协议下发送接收数据的例子程序.万分感谢 解决方案 解决方案二:VB.NET这方面的例子确实很少,LZ可以找些C#代码用专门的转换网站转过来看下就行了!解决方案三:没做过这类,可以上msdn看看.

Backbone View 之间通信的三种方式_javascript技巧

在上篇文章给大家介绍了Backbone中View之间传值的学习心得.本文重点给大家介绍Backbone View 之间通信的三种方式. 掌握一个 MVC 框架,最关键的一节就是掌握如何在各个 View 之间通信.之前用 Angular 时,觉得基于事件的通信方式 ($on, $emit, $boardcast) 或者 基于 service 的方式都非常好用.转战 Backbone 之后,由于对 Backbone 的事件机制理解不够且使用非常灵活,一直没找到一个好的通信方式.直到看见这篇文章,作者

网络通信丢包+IDC机房托管服务器之间通信不畅的问题

网络端口采用了1000M速率时候出现网络通信丢包+IDC机房托管服务器之间通信不畅. 网络故障: 交换机端口1000M,网卡也是1000M,网卡配置正常.ping时候间隔丢包. 表现为网络通信丢包,并且排除了其他网络设置故障. 故障原因:使用的网线非严格质量的超六类网线,网线质量无法达1000M. 解决方法:将交换机端口设置成100M端口:或者更换为超六类网线. 故障出现情况:网络端口采用了1000M速率时候出现网络通信丢包. 目录: 1.实例场景.网络端口采用了1000M速率时候出现网络通信丢

cad-CAD二次开发如何与Excel之间通信

问题描述 CAD二次开发如何与Excel之间通信 AutoCad中利用Ole已经包含了导入Excel表格功能,但我想自己编写一个小软件导入Excel表格,请问如何利用CAD提供的接口去开发?

mfc 窗口通信-mfc 窗口分割,窗口之间通信

问题描述 mfc 窗口分割,窗口之间通信 mfc 窗口分割后,如何实现一个窗口的控件与另一个窗口控件的通信 解决方案 关于切分视图,最佳的实践是通过共享的文档对象来共享数据. 解决方案二: 用父窗口做中转,子窗口都可以访问父窗口