Re: Copying string to byte array

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Sam Hobbs (samuel_at_social.rr.com_change_social_to_socal)
Date: 01/12/05

  • Next message: William Cruz: "Erasing nodes on a Tree View"
    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.


  • Next message: William Cruz: "Erasing nodes on a Tree View"

    Relevant Pages

    • Re: Structure conversion from C++ to VB-2008?
      ... Public Structure AmiVar ... Dim type As Integer ... Public *array as Single ... Public *string as String ...
      (microsoft.public.dotnet.languages.vb)
    • RE: Structure conversion from C++ to VB-2008?
      ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
      (microsoft.public.dotnet.languages.vb)
    • Help in French|Spanish|German translation.
      ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
      (microsoft.public.fox.helpwanted)
    • Re: passing a string to a dll
      ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
      (microsoft.public.vc.mfc)
    • Re: passing a string to a dll
      ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
      (microsoft.public.vc.mfc)