Show: Delphi C++
Display Preferences

__declspec(dllimport)

From RAD Studio
Jump to: navigation, search

Go Up to Keywords, Alphabetical Listing Index


Category

Modifiers (C++), Keyword Extensions, Storage Class Specifiers (C++)

Syntax

Form 1

 class __declspec( dllimport ) classDeclaration;

Form 2

 return_type __declspec( dllimport )functionDeclaration;

Form 3

 data_type __declspec( dllimport ) dataName;

The dllimport storage-class attribute is used for Microsoft C and C++ language compatibility. This attribute enables you to import functions, data, and objects to a DLL. The dllimport storage-class attribute can be applied to a template class or function, in which case it is considered to apply to every specialization of that template.

When a function is marked as dllimport, any supplied inline function body is ignored.

For example, importing a class:

   class _declspec(dllimport) A{
    private:
        int m_a;
        int m_b;
    public:
        int getA();
        int getB();
        void setA(int a);
        void setB(int b);
   };

Importing a global function:

 extern "C" __declspec(dllimport) void switch (int *a, int *b);
Note: Because a .DLL file is a binary file, the full declaration of the class/function is needed when importing.
Note: dllimport replaces the __import keyword, in the sense that it provides an easy and simple way of importing functions without the need of a .DEF file.

For template classes, see __declspec(dllexport).

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance