【发布时间】:2013-05-19 17:33:27
【问题描述】:
如何在 c# 中使用这个 dll 函数?我尝试了以下但我得到错误。 "外部组件抛出异常。"
我第一次用 C# 和 Delphi 做这个 PInvoke 的东西。
function HTTPGET(location:string):string; stdcall;
var
HTTP:TIdHttp;
begin
HTTP := TidHttp.Create(nil);
try
result := HTTP.Get(location);
finally
FreeAndNil(HTTP);
end;
end;
exports
HTTPGET;
begin
end.
namespace Test
{
class Program
{
[DllImport("project1.dll")]
public static extern string HTTPGET(string location);
static void Main(string[] args)
{
Console.WriteLine(HTTPGET("http://www.reuters.com/"));
}
}
}
【问题讨论】:
-
您确定 HTTP.Get() 与测试地址一起正常工作吗?
-
@thalm 那只是一个测试样本网站地址:)