__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, providing an easy and simple way of importing functions without needing a .DEF file.


See Also