.net - 在 Delphi 程序中托管 .NET 运行时

标签 .net delphi winapi com interop

我正在考虑在 Delphi 程序中使用一些 .NET 代码,我需要使用 .net 程序集和预定义函数使我的程序可扩展(我已经支持常规 DLL)。

经过网上大量搜索,我发现Managed-VCL ,但我还没准备好为我需要的东西支付 250 美元,我还发现一些新闻组的代码不完整且无法工作。

我正在使用 Delphi 2007 for win32。我可以使用什么来从具有预定义参数的程序集中动态执行函数?

类似于:

procedure ExecAssembly(AssemblyFileName:String; Parameters: Variant);

我只是想补充一点,我需要能够加载任意程序集(可能是特定文件夹中的所有程序集),因此创建 C# 包装器可能不起作用。

最佳答案

在 Jedi 代码库 (JCL) - 免费 - 有一个 Jcl DotNet.pas,其中包含一个 TJc ClrHost 类,可能会执行您想要的操作:

  TJclClrHost = class(TJclClrBase, ICorRuntimeHost)
  private
    FDefaultInterface: ICorRuntimeHost;
    FAppDomains: TObjectList;
    procedure EnumAppDomains;
    function GetAppDomain(const Idx: Integer): TJclClrAppDomain;
    function GetAppDomainCount: Integer;
    function GetDefaultAppDomain: IJclClrAppDomain;
    function GetCurrentAppDomain: IJclClrAppDomain;
  protected
    function AddAppDomain(const AppDomain: TJclClrAppDomain): Integer;
    function RemoveAppDomain(const AppDomain: TJclClrAppDomain): Integer; 
  public
    constructor Create(const ClrVer: WideString = '';
      const Flavor: TJclClrHostFlavor = hfWorkStation;
      const ConcurrentGC: Boolean = True;
      const LoaderFlags: TJclClrHostLoaderFlags = [hlOptSingleDomain]);
    destructor Destroy; override;
    procedure Start;
    procedure Stop;
    procedure Refresh;
    function CreateDomainSetup: TJclClrAppDomainSetup;
    function CreateAppDomain(const Name: WideString;
      const Setup: TJclClrAppDomainSetup = nil;
      const Evidence: IJclClrEvidence = nil): TJclClrAppDomain;
    function FindAppDomain(const Intf: IJclClrAppDomain; var Ret: TJclClrAppDomain): Boolean; overload;
    function FindAppDomain(const Name: WideString; var Ret: TJclClrAppDomain): Boolean; overload;
    class function CorSystemDirectory: WideString;
    class function CorVersion: WideString;
    class function CorRequiredVersion: WideString;
    class procedure GetClrVersions(VersionNames: TWideStrings); overload;
    class procedure GetClrVersions(VersionNames: TStrings); overload;
    property DefaultInterface: ICorRuntimeHost read FDefaultInterface implements ICorRuntimeHost;
    property AppDomains[const Idx: Integer]: TJclClrAppDomain read GetAppDomain; default;
    property AppDomainCount: Integer read GetAppDomainCount;
    property DefaultAppDomain: IJclClrAppDomain read GetDefaultAppDomain;
    property CurrentAppDomain: IJclClrAppDomain read GetCurrentAppDomain;
  end;

关于.net - 在 Delphi 程序中托管 .NET 运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/258875/

相关文章:

mysql - 忽略 TDateTime 中的毫秒(相同 TDateTime 值相减不为 0)

c# - 问答审计软件的设计模式

.net - 在代码中创建 NetTcpBinding 时如何设置 ReliableSession.MaxPendingChannels?

c# - 为什么 Thread.Start 会抛出 OutOfMemoryException

c++ - 在 Delphi 中实现 C DLL

c++ - 创建远程线程会使进程崩溃

c# - 在 session 中存储登录名和密码哈希是否安全?

delphi - Delphi保存到文本文件

winapi - Win32 弹出菜单可以响应滚轮吗?

winapi - Windows XP 和 Windows 7 中事件对象的不同行为