Re: Copying string to byte array
From: Sam Hobbs (samuel_at_social.rr.com_change_social_to_socal)
Date: 01/12/05
- Previous message: SteveC: "next day with dateadd"
- In reply to: Ken Halter: "Re: Copying string to byte array"
- Next in thread: Jeff Johnson [MVP: VB]: "Re: Copying string to byte array"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 12 Jan 2005 13:52:48 -0800
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:%23HOaHjO%23EHA.3932@TK2MSFTNGP10.phx.gbl...
> "Sam Hobbs" <samuel@social.rr.com_change_social_to_socal> wrote in message
> news:ecThecO%23EHA.1408@TK2MSFTNGP10.phx.gbl...
>>I am researching and learning ways to copy a sting with byte data to a
>>byte array and I at the moment I am confident I can figure out how to do
>>it. I
>
> '===================
> Private Sub Command1_Click()
> Dim sSomeString As String
> Dim btSomeByteArray() As Byte
> Dim iSomeCounter As Integer
>
> sSomeString = "Insert string data here" & vbCrLf & "More data"
>
> 'This places the contents of a string into a byte array
> 'You can use btSomeByteArray = sSomeString but that'll give you a
> Unicode byte array (every other element's 0 here)
> btSomeByteArray = StrConv(sSomeString, vbFromUnicode)
>
> For iSomeCounter = 0 To UBound(btSomeByteArray)
> Debug.Print btSomeByteArray(iSomeCounter)
> Next
>
> End Sub
> '===================
That does not seem to work either. Perhaps my testing mechanism is what is
erroneous, but the MSDN sample of the StrConv function seems clear that
vbFromUnicode converst to an ANSI string.
The problem is that the CryptEncrypt SDK function uses one parameter for
both input and output, so that the data is a string for input but definitely
not a string for output. For output, the data must be processed as byte
data, not anything that conforms to anything close to a string. The
encrypted data can even have embedded nulls.
So for example the data might be the following 8 bytes:
sSomeString = ChrW(&HF19C) + ChrW(&H5B72) + ChrW(&HE42E) + ChrW(&HA2D9)
I need to convert that (encrypted data such as that) to a byte array to
store it in the registry as binary data. VB tries to make things easy, but
when it does not make things easy, it takes two or three days to figure out
how to do something that would require just a few seconds of my time if I
were using C/C++.
However note that I am not asking for a solution; I am just asking for
verification that the code I posted won't satisfy the requirements.
- Previous message: SteveC: "next day with dateadd"
- In reply to: Ken Halter: "Re: Copying string to byte array"
- Next in thread: Jeff Johnson [MVP: VB]: "Re: Copying string to byte array"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|