VB6/VB.Net Programming Question - what am i doing wrong?

Discussion in 'ASP .Net' started by Salisha Khan, Jul 31, 2003.

  1. Salisha Khan

    Salisha Khan Guest

    Hey there,

    Can anyone please help with this problem?

    The function below works fine in VB6. For VB .NET the constants
    vbFromUnicode and vbUnicode no longer exist. The problem is the
    DecryptString method takes an ANSI String byref. In VB .NET you only have
    Unicode strings. All the string format conversion methods for VB .NET return
    the conversion in a Byte array not a string as in VB6. I can't pass a byte
    array to the ecryptString method. I've tried using declare and dllImport to
    declare the DecryptString as an ANSI function but it seems to have no
    effect. Maybe because DecryptString works directly on the byref string
    passed in instead of returning a string. In the .NET version here is my
    Declare:

    Private Declare Ansi Function DecryptString Lib

    "AxInterop.TDCIPH32Lib.dll" Alias "DecryptString" _

    (ByRef ciphertext As String, ByVal count As Integer) As Short

    below is the VB6 version that works:

    Private Function Decrypt(S As String, StrLength As Byte) As String

    Dim count As Long, status As Integer, strCfr As String

    Dim strANSIInput As String

    Dim i As Integer

    Dim Index As Integer

    TDciph321.DESReset

    ' convert to hex string

    For i = 1 To StrLength Step 2

    strCfr = strCfr & Chr("&H" & Mid(S, i, 2))

    Next

    ' convert to an ansi string

    strCfr = StrConv(strCfr, vbFromUnicode)

    ' decrypt the string

    status = TDciph321.DecryptString(strCfr, LenB(strCfr))

    ' convert back to Unicode

    strANSIInput = StrConv(strCfr, vbUnicode)

    Decrypt = strANSIInput

    End Function

    If anyone has any ideas that help I'd be greatly appreciative. Thanks in

    advance.



    Salisha
    Salisha Khan, Jul 31, 2003
    #1
    1. Advertising

  2. Salisha Khan

    JohnFol Guest

    I think you already have a reply on Google.

    http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=04ea01c3
    579c%24d3daea80%24a101280a%40phx.gbl&rnum=1&prev=/groups%3Fq%3Dansi%2Bunicod
    e%2BvbFromUnicode%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26scoring%3Dd


    "Salisha Khan" <> wrote in message
    news:3saWa.8$...
    > Hey there,
    >
    > Can anyone please help with this problem?
    >
    > The function below works fine in VB6. For VB .NET the constants
    > vbFromUnicode and vbUnicode no longer exist. The problem is the
    > DecryptString method takes an ANSI String byref. In VB .NET you only have
    > Unicode strings. All the string format conversion methods for VB .NET

    return
    > the conversion in a Byte array not a string as in VB6. I can't pass a byte
    > array to the ecryptString method. I've tried using declare and dllImport

    to
    > declare the DecryptString as an ANSI function but it seems to have no
    > effect. Maybe because DecryptString works directly on the byref string
    > passed in instead of returning a string. In the .NET version here is my
    > Declare:
    >
    > Private Declare Ansi Function DecryptString Lib
    >
    > "AxInterop.TDCIPH32Lib.dll" Alias "DecryptString" _
    >
    > (ByRef ciphertext As String, ByVal count As Integer) As Short
    >
    > below is the VB6 version that works:
    >
    > Private Function Decrypt(S As String, StrLength As Byte) As String
    >
    > Dim count As Long, status As Integer, strCfr As String
    >
    > Dim strANSIInput As String
    >
    > Dim i As Integer
    >
    > Dim Index As Integer
    >
    > TDciph321.DESReset
    >
    > ' convert to hex string
    >
    > For i = 1 To StrLength Step 2
    >
    > strCfr = strCfr & Chr("&H" & Mid(S, i, 2))
    >
    > Next
    >
    > ' convert to an ansi string
    >
    > strCfr = StrConv(strCfr, vbFromUnicode)
    >
    > ' decrypt the string
    >
    > status = TDciph321.DecryptString(strCfr, LenB(strCfr))
    >
    > ' convert back to Unicode
    >
    > strANSIInput = StrConv(strCfr, vbUnicode)
    >
    > Decrypt = strANSIInput
    >
    > End Function
    >
    > If anyone has any ideas that help I'd be greatly appreciative. Thanks in
    >
    > advance.
    >
    >
    >
    > Salisha
    >
    >
    >
    >
    >
    >
    >
    >
    >
    JohnFol, Aug 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miguel Dias Moura
    Replies:
    1
    Views:
    406
    Lars Netzel
    Jun 18, 2004
  2. Shapper
    Replies:
    3
    Views:
    338
    Angrez Singh
    May 9, 2005
  3. Leslie
    Replies:
    5
    Views:
    353
    dante
    Oct 20, 2003
  4. Amy G
    Replies:
    3
    Views:
    325
    Amy G
    Jan 19, 2004
  5. dgk
    Replies:
    4
    Views:
    249
Loading...

Share This Page