本篇文章主要介绍了"C#调用Delphi接口ITest = interface",主要涉及到interface,Delphi方面的内容,对于Delphijrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下:
首先创建一个delphi的DLL工程library testintfdll;{ Important note about DLL memory manageme...
首先创建一个delphi的DLL工程
library testintfdll;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
uintf in 'uintf.pas';
{$R *.res}
exports
GetImpl;
begin
end.
接下来声明并实现接口
unit uintf;
interface
uses Windows;
type
ITest = interface
['{000A0299-A27A-4D35-9721-419AE6E83869}']
procedure ShowMessage(msg: PAnsiChar); stdcall;
function Add(a, b: Integer): Integer; stdcall;
end;
TTest = class(TInterfacedObject, ITest)
protected
procedure ShowMessage(msg: PAnsiChar); stdcall;
function Add(a, b: Integer): Integer; stdcall;
end;
procedure GetImpl(out instance: ITest); stdcall;
implementation
procedure GetImpl(out instance: ITest);
begin
instance := TTest.Create;
end;
{ TTest }
function TTest.Add(a, b: Integer): Integer;
begin
Result := a + b;
end;
procedure TTest.ShowMessage(msg: PAnsiChar);
begin
MessageBox(0, msg, 'title', ID_OK);
end;
end.
最后在c#中调用