【发布时间】:2015-01-15 16:20:04
【问题描述】:
我在 VS2013 中使用 File/New Project/Class Library 创建了一个 DLL。然后我尝试在 Delphi 中动态加载它。但是 Delphi 返回NIL 用于过程GetProcAddress。
我的 C# 和 Delphi 代码看起来像我在下面发布的。在代码GetProcAddress 中返回NIL。如果我遗漏了什么,请告知。
C# 代码
using System;
namespace TestDLL
{
public class Class1
{
public static string EchoString(string eString)
{
return eString;
}
}
}
德尔福代码
Type
TEchoString = function (eString:string) : integer;stdcall;
function TForm1.EchoString(eString:string):integer;
begin
dllHandle := LoadLibrary('TestDLL.dll') ;
if dllHandle <> 0 then
begin
@EchoString := GetProcAddress(dllHandle, 'EchoString') ;
if Assigned (EchoString) then
EchoString(eString) //call the function
else
result := 0;
FreeLibrary(dllHandle) ;
end
else
begin
ShowMessage('dll not found ') ;
end;
end;
【问题讨论】:
-
我根据“非托管程序”的建议更改了代码。仍然没有运气。
-
我不明白那个评论。我回滚了你的编辑。请不要改变问题。请务必添加更多内容以要求澄清,但不要进行使历史完全无效的更改。
-
另外,如果你不发布假代码会更好。 C# 代码是假的。
-
谢谢大卫。我会记住这一点。
-
public static string EchoString(string eString:string)不是有效的 C#。而且它与 Delphi 代码不匹配。