A
Andrius B.
Hi all.
I would like to find out how to solve the problem using DLL functions
(written in Delphi) in VB.NET
The DLL contains a function
GetStatus (username: PChar; password: PChar; var status : PChar):integer;
it takes to input parameters (username and password) and returns 1 if
everything goes OK (status is return in variable "status" as string, like
"valid" or "expired"), and 0 if an exception occurs ("status" contains empty
string).
In VB this function is declared as
Declare Auto Function GetStatus Lib "mydll.dll" (ByVal username As IntPtr,
ByVal password As IntPtr, ByRef status As IntPtr) As Integer
The problem is how to use this function in a code.
As far as I know, the code shoul look smth like this:
Dim username as string="user1"
Dim password as string="pass1"
Dim status as New String(vbnullchar,255)
Dim userptr As New IntPtr
userptr = Marshal.StringToCoTaskMemAnsi(username & vbNullChar)
Dim passptr As New IntPtr
passptr = Marshal.StringToCoTaskMemAnsi(password & vbNullChar)
Dim statusptr As New IntPtr
statusptr = Marshal.StringToCoTaskMemAnsi(status & vbNullChar)
dim result as integer = GetStatus(userptr, passptr, statusptr)
status=marshal.PtrToStringAnsi(statusptr)
Is the code right or should be modified?
Thanks in advance.
I would like to find out how to solve the problem using DLL functions
(written in Delphi) in VB.NET
The DLL contains a function
GetStatus (username: PChar; password: PChar; var status : PChar):integer;
it takes to input parameters (username and password) and returns 1 if
everything goes OK (status is return in variable "status" as string, like
"valid" or "expired"), and 0 if an exception occurs ("status" contains empty
string).
In VB this function is declared as
Declare Auto Function GetStatus Lib "mydll.dll" (ByVal username As IntPtr,
ByVal password As IntPtr, ByRef status As IntPtr) As Integer
The problem is how to use this function in a code.
As far as I know, the code shoul look smth like this:
Dim username as string="user1"
Dim password as string="pass1"
Dim status as New String(vbnullchar,255)
Dim userptr As New IntPtr
userptr = Marshal.StringToCoTaskMemAnsi(username & vbNullChar)
Dim passptr As New IntPtr
passptr = Marshal.StringToCoTaskMemAnsi(password & vbNullChar)
Dim statusptr As New IntPtr
statusptr = Marshal.StringToCoTaskMemAnsi(status & vbNullChar)
dim result as integer = GetStatus(userptr, passptr, statusptr)
status=marshal.PtrToStringAnsi(statusptr)
Is the code right or should be modified?
Thanks in advance.