Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何在delphi prism中导入DLL?_.net_Dllimport_Delphi Prism_Oxygene - Fatal编程技术网

.net 如何在delphi prism中导入DLL?

.net 如何在delphi prism中导入DLL?,.net,dllimport,delphi-prism,oxygene,.net,Dllimport,Delphi Prism,Oxygene,我试图在我的delphi prism程序中导入dll,但以前从未这样做过。所以,在网上找到一些答案后,我把一些东西放在一起,如下所示,但不起作用 MyUtils = public static class private [DllImport("winmm.dll", CharSet := CharSet.Auto)] method timeBeginPeriod(period:Integer):Integer; external; protected publi

我试图在我的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

我回答了这个问题-

你很接近了

您不需要构造函数,因此可以删除它:

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
消息)。

Ck。非常感谢。我确实改变了你的答案,而且很有效。现在,我有一个问题。我可以把这个程序和winmm.dll一起在Linux上的mono下运行吗?它会像预期的那样工作吗?
  MyUtils = public static class
  public
    [DllImport("winmm.dll", CharSet := CharSet.Auto)]
    class method timeBeginPeriod(period:Integer):Integer; external;
  end;


MyUtils.timeBeginPeriod(1);