SpeedBWild
Programmer
I have been giving the task of taking a Delphi console application and making it into a Win32 DLL. From there I then need to be able to call the functions of the DLL from a VB.NET console application (during the testing stage).
I have several functions in my Delphi (Win32 DLL) and I can call all of them from the VB.NET console application. The one problem I am running into is for one of the functions I need to pass in a value and then based on that value run the function. This is not working. If I hard code in a value everything works, if I try to pass it in it fails. Below is the code I am using trying to pass in a value and use (sX)
Delphi code:
function GetData(sX :string; var sY :string) :integer;
begin
sY := GetData2('','','',sX,'');
result := 0;
end;
VB.net code:
<DllImport("C:\TestDLL.dll", EntryPoint:="GetData", SetLastError:=False, CharSet:=CharSet.Ansi, _
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Private Function GetData(ByVal pX As IntPtr, ByRef pY As IntPtr) As Int32
End Function
Dim MAXLen as int32 =255
Dim sXVal As String = "sssssss".PadRight(MAXLen , Chr(0))
Dim sYVal As String = "".PadRight(MAXLen , Chr(0))
Dim ptXVal As IntPtr = Marshal.StringToHGlobalAnsi(sXVal)
Dim ptYVal As IntPtr = Marshal.StringToHGlobalAnsi(sYVal)
Dim i As Int32 = -1
Try
i = GetData(ptXVal , ptYVal )
Catch e As System.Runtime.InteropServices.SEHException
Console.WriteLine(e.ErrorCode())
Console.WriteLine(e.Message)
Console.WriteLine(e.Source)
Catch e As Exception
Console.WriteLine(e.Message)
Finally
sYVal = Marshal.PtrToStringAnsi(ptYVal )
Marshal.FreeHGlobal(ptXVal)
Console.WriteLine(sYVal)
End Try
I am getting the System.Runtime.InteropServices.SEHException
exception. External component has thrown an exception.
Any ideas? If I am posting to the wrong forum, I apologize in advance. I'm not really sure where to post to.
Thanks,
Thanks
I have several functions in my Delphi (Win32 DLL) and I can call all of them from the VB.NET console application. The one problem I am running into is for one of the functions I need to pass in a value and then based on that value run the function. This is not working. If I hard code in a value everything works, if I try to pass it in it fails. Below is the code I am using trying to pass in a value and use (sX)
Delphi code:
function GetData(sX :string; var sY :string) :integer;
begin
sY := GetData2('','','',sX,'');
result := 0;
end;
VB.net code:
<DllImport("C:\TestDLL.dll", EntryPoint:="GetData", SetLastError:=False, CharSet:=CharSet.Ansi, _
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Private Function GetData(ByVal pX As IntPtr, ByRef pY As IntPtr) As Int32
End Function
Dim MAXLen as int32 =255
Dim sXVal As String = "sssssss".PadRight(MAXLen , Chr(0))
Dim sYVal As String = "".PadRight(MAXLen , Chr(0))
Dim ptXVal As IntPtr = Marshal.StringToHGlobalAnsi(sXVal)
Dim ptYVal As IntPtr = Marshal.StringToHGlobalAnsi(sYVal)
Dim i As Int32 = -1
Try
i = GetData(ptXVal , ptYVal )
Catch e As System.Runtime.InteropServices.SEHException
Console.WriteLine(e.ErrorCode())
Console.WriteLine(e.Message)
Console.WriteLine(e.Source)
Catch e As Exception
Console.WriteLine(e.Message)
Finally
sYVal = Marshal.PtrToStringAnsi(ptYVal )
Marshal.FreeHGlobal(ptXVal)
Console.WriteLine(sYVal)
End Try
I am getting the System.Runtime.InteropServices.SEHException
exception. External component has thrown an exception.
Any ideas? If I am posting to the wrong forum, I apologize in advance. I'm not really sure where to post to.
Thanks,
Thanks