Hi friends
what is a dll import
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
AlanRank #669 · 3.6K reputationPosted Sep 30, 2007, 1:49 AM EDT
In order to call static functions (typically written in C) which are exported by unmanaged dlls such as Win32 API funtions, then managed code needs a mechanism - known as platform invoke - to make the call and to marshal data between the two environments.
The DllImport attribute is used to indicate to the managed compiler that the implementation of a method can be found in a particular unmanaged dll and (optionally) to specify other information that the CLR may need to call such a method successfully such as its precise name and calling convention. Apart from the method's signature, no implementation is provided by the managed code itself.
Posted Oct 15, 2007, 1:28 AM EDT
The dllexport and dllimport storage-class attributes are Microsoft-specific extensions to the C and C++ languages. They enable you to export and import functions, data, and objects to and from a DLL.
These attributes explicitly define the DLL's interface to its client, which can be the executable file or another DLL. Declaring functions as dllexport eliminates the need for a module-definition (.DEF) file, at least with respect to the specification of exported functions. Note that dllexport replaces the __export keyword.
If a class is marked declspec(dllexport), any specializations of class templates in the class hierarchy are implicitly marked as declspec(dllexport). This means templates are explicitly instantiated and its members must be defined.
dllexport of a C++ function will expose the function with C++ name mangling. If C++ name mangling is not desired, either use a .def file (
EXPORTS keyword) or declare the function as extern "C".The declaration of dllexport and dllimport must use extendedattribute syntax and the __declspec keyword.
// Example of the dllimport and dllexport class attributes __declspec( dllimport ) int i; __declspec( dllexport ) void func();Alternately, to make your code more readable, you can use macro definitions:
#define DllImport __declspec( dllimport ) #define DllExport __declspec( dllexport ) DllExport void func(); DllExport int i = 10; DllImport int j; DllExport int n;