Sunday, September 19, 2010

creating dll of C using visual studio for plateform invoke form C sharp.

If  you approach to write CUDA program or some other application. For which you are required to build dll of C program such that you could create the GUI for that application in language like C sharp.


For this structure of your C program is supposed to be as::

  extern "C"             //
       {      
           __declspec(dllexport)  returntype funtionname (...)
                   {
                   ....................................the boby of your funtion................

                   }
         }
1.extern "C":::extern "C" is meant to be recognized by a C++ compiler and to notify the compiler that the noted function is (or to be) compiled in C style..since you are working in VC++ hence its good to write.


2.__declspec(dllexport):: when we pass a function to a dll it is always necessary to tell which function is to be include  and which is not required.
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.

 STEP 2: making DLL:
visual studio> project > project property> Configuration property> configuration type=Dynamic Library (.dll)


No comments:

Post a Comment