0

好吧,这是我的代码:

Public Sub WriteString(ByRef nString As String) 
Dim sBytes() As Byte
Dim sLength As Long

sLength = Len(nString)
sBytes = StrConv(nString, vbFromUnicode)

WriteLong sLength

If sLength <= 0 Then Exit Sub

If WriteHead + sLength - 1 > BufferSize Then Allocate sLength

CopyMemory buffer(WriteHead), sBytes(0), sLength
WriteHead = WriteHead + sLength
End Sub

Public Function ReadString(Optional MoveReadHead As Boolean = True) As String 
Dim sLength As Long
Dim sBytes() As Byte

sLength = ReadLong(False)
If sLength <= 0 Then
    If MoveReadHead Then ReadHead = ReadHead + 4
    Exit Function
End If

ReDim sBytes(sLength - 1)

CopyMemory sBytes(0), buffer(ReadHead + 4), sLength

ReadString = StrConv(sBytes, vbUnicode)
If MoveReadHead Then ReadHead = ReadHead + sLength + 4

Exit Function
End Function

问题是,当我写一个字符串(例如“ééé”)并尝试阅读时,我的应用程序崩溃了。我该如何解决这个问题?问题出现在“CopyMemory”中。

4

0 回答 0