Using the DllImport 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.