vb.net upgrade:
Salisha,
You can use the SYstem.Runtime.InteropServices.Marshal
class for this operation.
Declare the library function in the following way:
Private Declare Ansi Function DecryptString Lib
"AxInterop.TDCIPH32Lib.dll" Alias "DecryptString" _
(ByVal pCiphertext As IntPtr, ByVal count As Integer)
As Short
Then you can use the Marshal.StringToHGlobalAnsi function
to convert your string into an Ansi string.
This function retruns an IntPtr which u can pass to the
library function.
To convert the IntPtr back to a string you can use the
Marshal.PtrToStringAnsi function.
Note that you also have to free your alocated memory after
using it. You can do this by using the Marshal.FreeHGlobal
function. (According to the help on MSDN you should use
FreeCoTaskMem, but I hope that's a typo).
Gert-Jan.
[quoted text, click to view] >-----Original Message-----
>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
>
>
>
>
>
>
>
>
>
>
>.
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
Thank you for the response. This is the first one I've gotten that's made
any sense. I see where you are going with this. The only problem is the
DecryptString method is called from an instance of object:
Public WithEvents TDciph321 As AxTDCIPH32Lib.AxTDciph32
Its not a static function call. The compiler will not let me pass an
IntPtr like this:
TDciph321.DecryptString(intPtr, count)
it complains i have an IntPtr where i need a String.
I can only call it as if it were a static method: DecryptString(intPtr,
count)
This is obviously not right and throws an exception, no entry point for
DecryptString found.
Is there anyway to force a method call on an instance to accept the IntPtr?
Thanks much
[quoted text, click to view] "Gert-Jan Messchendorp" <messcheg@hotmail.com> wrote in message
news:04ea01c3579c$d3daea80$a101280a@phx.gbl...
> Salisha,
>
> You can use the SYstem.Runtime.InteropServices.Marshal
> class for this operation.
>
> Declare the library function in the following way:
>
> Private Declare Ansi Function DecryptString Lib
>
> "AxInterop.TDCIPH32Lib.dll" Alias "DecryptString" _
>
> (ByVal pCiphertext As IntPtr, ByVal count As Integer)
> As Short
>
> Then you can use the Marshal.StringToHGlobalAnsi function
> to convert your string into an Ansi string.
> This function retruns an IntPtr which u can pass to the
> library function.
>
> To convert the IntPtr back to a string you can use the
> Marshal.PtrToStringAnsi function.
>
> Note that you also have to free your alocated memory after
> using it. You can do this by using the Marshal.FreeHGlobal
> function. (According to the help on MSDN you should use
> FreeCoTaskMem, but I hope that's a typo).
>
>
> Gert-Jan.
>
>
>
> >-----Original Message-----
> >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
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >.
> >