我试图将delphi dll导入我的vb.net项目
这是我的代码:
Private Declare Function AddIntegers Lib "C:\Program Files (x86)\Borland\Delphi6\Projects\first dll\Project2.dll" Alias "AddIntegers" (ByVal a As Integer, ByVal b As Integer) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ii As Integer = AddIntegers(1, 3)
MsgBox(ii)
End Sub
这是delphi库代码:
library MyFirstLibrary;
uses
SysUtils,
Classes;
{$R *.res}
function AddIntegers(_a, _b: integer): integer; stdcall;
begin
Result := _a + _b;
end;
exports
AddIntegers;
begin
end.
有一个EntryPointNotFoundException:
Unable to find an entry point named 'AddIntegers' in DLL 'C:\Program Files (x86)\Borland\Delphi6\Projects\first dll\Project2.dll'.":""
如何修复EntryPointNotFoundException(我的delphi代码中存在AddIntegers函数)? (vb.net或c#)
答案 0 :(得分:5)
我的猜测是你正在加载一个不同的库。您正在加载Project2.dll
,而您的Delphi库在您在问题中发布的代码中被称为MyFirstLibrary.dll
。
答案 1 :(得分:0)
尝试直接使用DllImport
并应用不同的调用约定修饰符:
<DllImport("C:\Program Files (x86)\Borland\Delphi6\Projects\first dll\Project2.dll", CallingConvention:=CallingConvention.StdCall)> _
Private Shared Function AddIntegers(ByVal a As Integer, ByVal b As Integer) As Integer