Calling a delphi dll from VB.net
-
Hi all, Please provide steps to call a Delphi dll from vb.net. Any help is very much apprecited. Thanks alot. Following I have tried and no luck. 1) Added the DLL as a refernce to the project. -Shows an error message "Please MAke Sure that the file is accessible , and that it is a valid assembly or COM Component" 2) Used the DllImport method of System.Runtime.InteropServices
<DllImport("delphiProgram.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> _
Public Shared Function TestFunction(ByVal strTif As String) As Long-- Runtime it shows an error message "Unable to load DLL 'delphiProgram.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" 3) used the tlbimp.exe to make the dll as an interop -- Shows a message 'delphiProgram.dll' is not a valid type library. Thank you. Regards, Rijz
-
Hi all, Please provide steps to call a Delphi dll from vb.net. Any help is very much apprecited. Thanks alot. Following I have tried and no luck. 1) Added the DLL as a refernce to the project. -Shows an error message "Please MAke Sure that the file is accessible , and that it is a valid assembly or COM Component" 2) Used the DllImport method of System.Runtime.InteropServices
<DllImport("delphiProgram.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> _
Public Shared Function TestFunction(ByVal strTif As String) As Long-- Runtime it shows an error message "Unable to load DLL 'delphiProgram.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" 3) used the tlbimp.exe to make the dll as an interop -- Shows a message 'delphiProgram.dll' is not a valid type library. Thank you. Regards, Rijz
The .DLL has to be in the same folder as your .EXE or in a folder on the PATH environment variable. Chances are, it's not in either. You can add the .DLL to your project and, in the Properties window under "Copy to Output Directory", make sure it says "Copy Always" so the .DLL ends up in your project Debug or Release folder with your .EXE.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hi all, Please provide steps to call a Delphi dll from vb.net. Any help is very much apprecited. Thanks alot. Following I have tried and no luck. 1) Added the DLL as a refernce to the project. -Shows an error message "Please MAke Sure that the file is accessible , and that it is a valid assembly or COM Component" 2) Used the DllImport method of System.Runtime.InteropServices
<DllImport("delphiProgram.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> _
Public Shared Function TestFunction(ByVal strTif As String) As Long-- Runtime it shows an error message "Unable to load DLL 'delphiProgram.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" 3) used the tlbimp.exe to make the dll as an interop -- Shows a message 'delphiProgram.dll' is not a valid type library. Thank you. Regards, Rijz
Tested with Lazarus;
library project1;
{$mode objfpc}{$H+}
uses
Classes;procedure DoHelloWorld(var Source: string) stdcall; export;
begin
Source := 'Hello world :)';
end;exports DoHelloWorld;
begin
end.Imports System.Runtime.InteropServices
Imports System.TextModule Module1
\_ Public Sub DoHelloWorld(ByRef Source As StringBuilder) End Sub Sub Main() Dim sb As New StringBuilder() DoHelloWorld(sb) Console.WriteLine(sb.ToString()) Console.ReadKey() End Sub
End Module
Bastard Programmer from Hell :suss: