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

S

Salisha Khan

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top