Home > Software engineering >  Questions about using vb copymemory function
Questions about using vb copymemory function

Time:10-31

I want to test the use copymemory conversion between string and fixed-length byte array functions, see the following procedures, see the runtime program crashes, please masters teach you,


Dim bt (0 To 15) As Byte
Dim strTemp As String
Dim intTemp As Integer

StrTemp="wangxiaofeng"
CopyMemory bt (0), StrConv (strTemp, vbFromUnicode), LenB (StrConv (strTemp, vbFromUnicode))

CopyMemory strTemp, bt, 16

MsgBox strTemp

CodePudding user response:

What did your CopyMemory statement statement?
Refer to this

CodePudding user response:

reference 1st floor Veron_04 response:
your CopyMemory statement is how the statement?
Refer to this


My function declaration is as follows:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any Source, As Any, ByVal Length As Long)

CodePudding user response:

 Dim bt (0 To 15) As Byte 
Dim strTemp As String
Dim intTemp As Integer
StrTemp="wangxiaofeng"
CopyMemory bt (0), StrConv (strTemp, vbFromUnicode), LenB (StrConv (strTemp, vbFromUnicode))
MsgBox strTemp

CodePudding user response:

The
reference 3 floor zdingyun response:
 Dim bt (0 To 15) As Byte 
Dim strTemp As String
Dim intTemp As Integer
StrTemp="wangxiaofeng"
CopyMemory bt (0), StrConv (strTemp, vbFromUnicode), LenB (StrConv (strTemp, vbFromUnicode))
MsgBox strTemp


This code is a line less than I, I was meant to assign values to the byte array, and returns to the string to see, this process is correct,

CodePudding user response:

reference 4 floor u011661466 response:
Quote: reference zdingyun reply: 3/f

 Dim bt (0 To 15) As Byte 
Dim strTemp As String
Dim intTemp As Integer
StrTemp="wangxiaofeng"
CopyMemory bt (0), StrConv (strTemp, vbFromUnicode), LenB (StrConv (strTemp, vbFromUnicode))
MsgBox strTemp


This code is a line less than I, I was meant to assign values to the byte array, and returns to the string to see, this process is correct,

That also need not CopyMemory:
 Option Explicit 
Dim strData As String
Dim yTemp () As Byte

Private Sub Command2_Click () 'byte array to a string
StrData=https://bbs.csdn.net/topics/StrConv (yTemp vbUnicode)
Text2=strData
End Sub

Private Sub Form_Load ()
Text1=""
Text2=""
End Sub

Private Sub Command1_Click ()
'character to the characters of the byte arrayDim sTemp As String
'the sTemp="for electronic engineer advice!!!!!! [1] to plan his own way, don't follow! Decision-making arrangements according to individual ideal, what most people do not expect to become member or professor, but to live well, great, so, will need to be careful to arrange their own path, from which industry, gradually understanding of the industry, don't jump, don't moved for little pay, especially in the long run, the money doesn't consider as what, when you are on an industry have so a few years of experience, after the money was not problem, frequent turmoil is not the best policy, finally clear about which industry to you, will always be a novice! [2] can do technology, must not indulge in technology, never tried to study technology! Give yourself a lot of pressure, if your mind all on this above, so destined to kong yiji kind of character you are going to be! Enough is enough, because technology is only one of the pillars of your future in the future, but also is not the biggest pillar, unless you are willing to only old or an engineer!"
STemp="1234567890 to electronic engineer advice!"
YTemp=StrConv (sTemp, vbFromUnicode)
Text1=sTemp
Text3=Len (sTemp)
Text4=UBound (yTemp)
End Sub

CodePudding user response:

reference 5 floor zdingyun reply:
Quote: refer to 4th floor u011661466 response:

Quote: refer to the third floor zdingyun response:

 Dim bt (0 To 15) As Byte 
Dim strTemp As String
Dim intTemp As Integer
StrTemp="wangxiaofeng"
CopyMemory bt (0), StrConv (strTemp, vbFromUnicode), LenB (StrConv (strTemp, vbFromUnicode))
MsgBox strTemp


This code is a line less than I, I was meant to assign values to the byte array, and returns to the string to see, this process is correct,

That also need not CopyMemory:
 Option Explicit 
Dim strData As String
Dim yTemp () As Byte

Private Sub Command2_Click () 'byte array to a string
StrData=https://bbs.csdn.net/topics/StrConv (yTemp vbUnicode)
Text2=strData
End Sub

Private Sub Form_Load ()
Text1=""
Text2=""
End Sub

Private Sub Command1_Click ()
'character to the characters of the byte arrayDim sTemp As String
'the sTemp="for electronic engineer advice!!!!!! [1] to plan his own way, don't follow! Decision-making arrangements according to individual ideal, what most people do not expect to become member or professor, but to live well, great, so, will need to be careful to arrange their own path, from which industry, gradually understanding of the industry, don't jump, don't moved for little pay, especially in the long run, the money doesn't consider as what, when you are on an industry have so a few years of experience, after the money was not problem, frequent turmoil is not the best policy, finally clear about which industry to you, will always be a novice! [2] can do technology, must not indulge in technology, never tried to study technology! Give yourself a lot of pressure, if your mind all on this above, so destined to kong yiji kind of character you are going to be! Enough is enough, because technology is only one of the pillars of your future in the future, but also is not the biggest pillar, unless you are willing to only old or an engineer!"
STemp="1234567890 to electronic engineer advice!"
YTemp=StrConv (sTemp, vbFromUnicode)
Text1=sTemp
Text3=Len (sTemp)
Text4=UBound (yTemp)
End Sub


Trouble is that this place, I want to use a fixed length of the byte array, not a dynamic array, so using strconv function have problem, can only use copymemory.

CodePudding user response:

LZ carefully read this post:
http://bbs.csdn.net/topics/310268078
  • Related