VB6中文关于WinSock获取数据 中文乱码,字母和数字就能正确显示

大哥大姐们请帮忙,小弟研究VB时间不多,迷糊中。谢谢老首先:这种不行,不能显示PrivateSubWinsock1_DataArrival(ByValbytesTotal... 大哥大姐们请帮忙,小弟研究VB时间不多,迷糊中。谢谢老 首先:
这种不行,不能显示
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim dd As String
Winsock1.GetData dd
Text1.Text = dd
End Sub下面这种:
显示时中文乱码,字母和数字可以正确显示
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strGetData() As Byte
Winsock1.GetData strGetData, vbArray + vbByte

For j = 0 To UBound(strGetData)
Text1.Text = Text1.Text & Chr(strGetData(j))
Next
End Sub
大哥大姐们请帮忙,小弟研究VB时间不多,迷糊中。谢谢老
展开
 我来答
匿名用户
2013-07-12
展开全部
不知道你是不是抓取网页的时候遇到的乱码,如果是,下面提供我的解决方法,如果不是,我就帮不了你哈:(用MultiByteToWideChar) Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long Private Sub YuZhe_WinSocket_DataArrival(ByVal bytesTotal As Long)
Dim strmyfile As String Dim SocketPageUrlCode As Long
Dim myfile() As Byte
YuZhe_WinSocket.GetData myfile, vbArray + vbByte, bytesTotal
strmyfile = YuZhe_WinSocket_Decode(myfile, 65001) ‘65001即为utf-8页面编码,gb2312--936
SocketPageData = SocketPageData & strmyfile
End Sub Private Function YuZhe_WinSocket_Decode(bUTF8() As Byte, iCodeID As Long) As String '二进制解析为UTF8
Dim lRet As Long
Dim lLen As Long
Dim lBufferSize As Long
Dim sBuffer As String
Dim bBuffer() As Byte
lLen = UBound(bUTF8) + 1
If lLen = 0 Then Exit Function
lBufferSize = lLen * 2
sBuffer = String$(lBufferSize, Chr(0))
lRet = MultiByteToWideChar(iCodeID, 0, VarPtr(bUTF8(0)), lLen, StrPtr(sBuffer), lBufferSize)
If lRet <> 0 Then
sBuffer = Mid(sBuffer, 1, lRet)
End If
YuZhe_WinSocket_Decode = sBuffer
End Function
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-07-12
展开全部
试试这个Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim bb(1 To bytesTotal) As Byte Dim DD As String Winsock1.GetData bb() DD = StrConv(bb(), vbFromUnicode)End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式