Today I create a dll in C on microsoft visual studio 2010.Following are the snapshots of steps which we take during creating a dll in microsoft visual studio 2010.
After clicking finish we see several type of files in the project which are shown in below snapshot.
where temp is the name of project & cpp file.
In the temp.cpp file we need to write the definition of function & header files included in function writen in either temp.cpp or temp.h.Then we need to run which create temp.lib file in directory.By adding this temp.lib file into any project we easily use the dll only by adding used header in function into .h or .cpp file & calling the function.
we need to write __declspec (dllexport) for Cpp file & extern "C" __declspec (dllexport) for C file while creating library.
Here are some important keyword used in creating and using DLL:-
__declspec:-It is a storage class specifier .It uses various storage class attribute to enable various usage of it.
dllexport:-dllexport storage class attribute enables us to export function ,data & objects from the dll.Declaring function as dllexport eliminates the need for a module definition 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 specialization of class templates in the class hierarchy are implicitly marked as declspec(dllexport ).This means templates are explicitly instantiated and its member must be defined .The declaration of dllexport must use extended attribute syntax and the _declspec keyword.
Ex:-
dllimport:-dllimport storage class attribute enables us to import function ,data & objects from the dll.The declaration of dllimport must use extended attribute syntax and the _declspec keyword.
Ex:-
In the temp.cpp file we need to write the definition of function & header files included in function writen in either temp.cpp or temp.h.Then we need to run which create temp.lib file in directory.By adding this temp.lib file into any project we easily use the dll only by adding used header in function into .h or .cpp file & calling the function.
we need to write __declspec (dllexport) for Cpp file & extern "C" __declspec (dllexport) for C file while creating library.
Here are some important keyword used in creating and using DLL:-
__declspec:-It is a storage class specifier .It uses various storage class attribute to enable various usage of it.
dllexport:-dllexport storage class attribute enables us to export function ,data & objects from the dll.Declaring function as dllexport eliminates the need for a module definition 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 specialization of class templates in the class hierarchy are implicitly marked as declspec(dllexport ).This means templates are explicitly instantiated and its member must be defined .The declaration of dllexport must use extended attribute syntax and the _declspec keyword.
Ex:-
__declspec( dllexport ) void func();
dllimport:-dllimport storage class attribute enables us to import function ,data & objects from the dll.The declaration of dllimport must use extended attribute syntax and the _declspec keyword.
Ex:-
__declspec( dllimport ) int i;
naked:-For the function declared with the naked attribute ,the compiler generates code without prolog and apilog code.Naked functions are particularly useful in writing virtual device driver.The naked code is only valid on x86 and is not available on x64 or itanium. Ex:-__declspec( naked ) int func( formal_parameters ) {}
No comments:
Post a Comment