【问题标题】:How to import DLL in delphi-prism?如何在delphi-prism中导入DLL?
【发布时间】:2012-10-31 15:05:44
【问题描述】:

我正在尝试在我的 delphi-prism 程序中导入 dll,但以前从未这样做过。所以,在网上找到了一些答案后,我整理了一些东西如下但不起作用。

  MyUtils = public static class
  private
    [DllImport("winmm.dll", CharSet := CharSet.Auto)]
    method timeBeginPeriod(period:Integer):Integer; external;
  protected
  public
    constructor;
  end;

这是我的使用方法:

var tt := new MyUtils;
tt.timeBeginPeriod(1);

当我运行我的程序时,我不断收到以下错误。

  • “MyUtils”不提供可访问的构造函数。
  • “System.Object”在表达式中不包含“timeBeginPeriod”的定义 “tt.timeBeginPeriod。”

我做错了什么? delphi-prism中如何导入dll?

我关注了这个 stackoverflow 问题 - Delphi Prism getting Unknown Identifier "DllImport" error

【问题讨论】:

    标签: .net dllimport delphi-prism oxygene


    【解决方案1】:

    你很亲密。

    你不需要构造函数,所以你可以删除它:

    MyUtils = public static class
    private
      [DllImport("winmm.dll", CharSet := CharSet.Auto)]
      method timeBeginPeriod(period:Integer):Integer; external;
    protected
    public
    end;
    

    如果您从声明它的单元外部调用timeBeginPeriod 函数,则需要将其可见性更改为public

    你也不需要创建实例来调用函数:

    MyUtils.timeBeginPeriod(1);
    

    我使用声明并使用SendMessage 的应用程序对此进行了测试,因此我可以轻松检查以确保它确实有效(我向同一表单上的编辑控件发送了EM_SETTEXT 消息)。

    【讨论】:

      【解决方案2】:
        MyUtils = public static class
        public
          [DllImport("winmm.dll", CharSet := CharSet.Auto)]
          class method timeBeginPeriod(period:Integer):Integer; external;
        end;
      
      
      MyUtils.timeBeginPeriod(1);
      

      【讨论】:

      • CK。谢谢你。我确实按照您的答案进行了更改,并且可以正常工作。现在,我确实有一个问题。我可以使用这个程序并在 Linux 上与 winmm.dll 一起在单声道下运行它吗?它会按预期工作吗?
      猜你喜欢
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多