Oxygene 中的 DLL 示例

发布于 2024-08-10 02:02:13 字数 109 浏览 3 评论 0原文

有人可以告诉我在哪里可以找到如何在 Oxygene for .NET 中制作 DLL (WindowsControlLibrary) 的示例吗?
在旧的 Delphi 中,您可以创建一个导出部分。

Can somebody tell me where to find an example in how to make an DLL (WindowsControlLibrary) in Oxygene for .NET?
In the old Delphi, you make an export section.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

合约呢 2024-08-17 02:02:13

要使用 Delphi Prism 创建非托管 DLL 导出并使用 Delphi 2010 调用它,您必须执行以下操作:

在 Delphi Prism 中:

  1. 文件 | DLL 导出新 |项目
  2. 在左侧的树视图中,选择 Delphi Prism
  3. 选择 Windows 类库

按确定。

这将为 Windows 类库创建模板

右键单击​​项目“ClassLibraryX”并选择属性:

  1. 在“兼容性”下选择“允许不安全代码”
  2. 在“生成”下,找到“常规”部分并将 CPU 类型更改为“x86”
  3. 右键单击​​“创建的“ClassLibraryX”选项卡并选择“保存所选项目”

这会将项目设置为支持 UnmanagementExportAttribute。

然后在代码中您需要创建一个类方法。在下面的示例中,我添加了对 System.Windows.Forms 的引用。

namespace ClassLibrary2;

interface

type
  Class1 = public class
  private
  protected
  public
    [UnmanagedExport('ShowMessage')]
    class method ShowMessage(aMsg : String);
  end;

implementation

class method Class1.ShowMessage(aMsg : String);
begin
 System.Windows.Forms.MessageBox.Show(aMsg);  
end;

end.

使用 PEViewer,我使用 JCL 中提供的那个作为示例,您应该能够查看新的导出。在上面的例子中“ShowMessage”

To create an Unmanaged DLL Export using Delphi Prism and call it with Delphi 2010 you must do the following:

In Delphi Prism:

  1. File | New | Project
  2. In the Tree View on the Left, select Delphi Prism
  3. Select Windows Class Library

Press OK.

This will create the template for the Windows Class Library

Right Click on the Project "ClassLibraryX" and Select Properties:

  1. Under Compatibility select "Allow unsafe code"
  2. Under Build, find the General Section and change CPU Type to "x86"
  3. Right Click on the "ClassLibraryX" tab that was created and select "Save selected Items"

This sets up the project to support the UnmanagedExportAttribute.

Then in the code you will need to create a class method. In the example below I added a reference to System.Windows.Forms.

namespace ClassLibrary2;

interface

type
  Class1 = public class
  private
  protected
  public
    [UnmanagedExport('ShowMessage')]
    class method ShowMessage(aMsg : String);
  end;

implementation

class method Class1.ShowMessage(aMsg : String);
begin
 System.Windows.Forms.MessageBox.Show(aMsg);  
end;

end.

Using a PEViewer, I used the one that ships as an example in JCL, you should be able to see the new export. In the above exampele "ShowMessage"

胡大本事 2024-08-17 02:02:13

如果你想让它与delphi兼容,那么你必须指定一个“stdcall”调用约定命名

空间ClassLibrary2;

接口

类型
Class1 = 公共类

私有

受保护

公共

[UnmanagedExport('ShowMessage'), System.Runtime.InteropServices.CallingConvention.StdCall]

类方法 ShowMessage(aMsg : String);
结尾;

实现

类方法 Class1.ShowMessage(aMsg : String);

开始

System.Windows.Forms.MessageBox.Show(aMsg);

结尾;

结尾。

If you whant to make it compatible with delphi then you have to indicate a "stdcall" Calling Convention

namespace ClassLibrary2;

interface

type
Class1 = public class

private

protected

public

[UnmanagedExport('ShowMessage'), System.Runtime.InteropServices.CallingConvention.StdCall]

class method ShowMessage(aMsg : String);
end;

implementation

class method Class1.ShowMessage(aMsg : String);

begin

System.Windows.Forms.MessageBox.Show(aMsg);

end;

end.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文