Importing Functions from Libraries

To import routines from a dynamically loadable library (.DLL), attach a directive of the form external stringConstant;

to the end of a normal procedure or function header, where stringConstant is the name of the library file in single quotation marks. For example, on Win32

function SomeFunction(S: string): string; external 'strlib.dll'; imports a function called SomeFunction from strlib.dll.

You can import a routine under a different name from the one it has in the library. If you do this, specify the original name in the external directive:

external stringConstantl name stringConstant2;

where the first stringConstant gives the name of the library file and the second stringConstant is the routine's original name.

The following declaration imports a function from user32.dll (part of the Win32 API).

function MessageBox(HWnd: Integer; Text, Caption: PChar; Flags: Integer): Integer; stdcall; external 'user32.dll' name 'MessageBoxA';

The function's original name is MessageBoxA, but it is imported as MessageBox.

Instead of a name, you can use a number to identify the routine you want to import:

externalstringConstantindexintegerConstant;

where integerConstant is the routine's index in the export table.

In your importing declaration, be sure to match the exact spelling and case of the routine's name. Later, when you call the imported routine, the name is case-insensitive.

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