Using the Dll Import Custom Attribute

You can call unmanaged Win32 APIs (and other unmanaged code) by prefixing the function declaration with the DllImport custom attribute. This attribute resides in the System. Runtime.InteropServices namespace, as shown below:

Program HellowWorld2;

// Don't forget to include the InteropServices unit when using the DllImport attribute.

uses System.Runtime.InteropServices;

[DllImport('user32.dll')]

function MessageBeep(uType : LongWord) : Boolean; external; begin

MessageBeep(LongWord(-1));

end.

Note the external keyword is still required, to replace the block in the function declaration. All other attributes, such as the calling convention, can be passed through the DllImport custom attribute.

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment