Visual C++ Language Reference
dllexport, dllimport

Microsoft Specific

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.

__declspec( dllimport ) declarator
__declspec( dllexport ) declarator
Remarks

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 extended attribute syntax and the __declspec keyword.

Example

// 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;

For additional information, see:

END Microsoft Specific

See Also

Reference



Community Content

Stanley Roark
error: __dllspec not defined?

Visual C++ 2005 does not recognize any of the functions/macros/keywords/identifiers.

What headers are these identifiers declared in?


[tfl - 06 08 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at

http://www.microsoft.com/communities/newsgroups/en-us/ . You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C &
SQL Server :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C &
.NET Framework :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C &


Page view tracker