문제

am sending data using this code in vb6

cds.dwData = CLng(RegisterWindowMessage("MyWMCopyData"))
cds.cbData = Len(Message) * 2 ' characters are 2-bytes each
cds.lpData = StrPtr(Message) ' access the string's character buffer directly
' Send the string.
Dim i As Long:i = SendMessage(lHwnd, WM_COPYDATA, MainForm.hwnd, cds)

can you help me with the code to receive it vurrently i have this

Dim B() As Byte
ReDim B(0 To tCDS.cbData - 1) As Byte
CopyMemory B(0), ByVal tCDS.lpData, tCDS.cbData
Dim sData As String
sData = Trim$(StrConv(B, vbUnicode))

if i send Hello, i get it as H e l l o

도움이 되었습니까?

해결책

You're mixing up string conversions.

Your sending code sends a pointer to the full unicode string. When you receive it, you then pass it to StrConv(..., vbUnicode) which converts from ANSI to unicode, "corrupting" the string data.

To resolve this, you just need to assign the final byte array directly to the string:

sData = B

Alternatively, you can allocate the string length and copy directly into it:

Dim sData As String  
sData = String(tCDS.cbData / 2, vbNullChar) ' characters are 2-bytes each
CopyMemory ByVal StrPtr(sData), ByVal tCDS.lpData, tCDS.cbData

다른 팁

The string is in Unicode format

In uncode, each single character occupy 2 bytes, as ASCII was just 1 byte, so i think vb fill the another byte with white space (maybe)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top