I am trying to import dll in my delphi-prism program and never done it before. So, after finding some answer online, I put something together as follows but doesn't work.
MyUtils = public static class
private
[DllImport("winmm.dll", CharSet := CharSet.Auto)]
method timeBeginPeriod(period:Integer):Integer; external;
protected
public
constructor;
end;
Here is how I use it:
var tt := new MyUtils;
tt.timeBeginPeriod(1);
When I run my program, I keep getting the following errors.
What am I doing wrong? How do you import dll in delphi-prism?
I followed this stackoverflow question - Delphi Prism getting Unknown Identifier "DllImport" error
You're very close.
You don't need the constructor, so you can remove it:
MyUtils = public static class
private
[DllImport("winmm.dll", CharSet := CharSet.Auto)]
method timeBeginPeriod(period:Integer):Integer; external;
protected
public
end;
If you're calling the timeBeginPeriod
function from outside the unit where it's declared, you need to change it's visibility to public
.
You also don't need to create an instance to call the function:
MyUtils.timeBeginPeriod(1);
I tested this with an app that declared and used SendMessage
instead, so I could easily check to make sure it actually worked (I sent an EM_SETTEXT
message to an Edit control on the same form).