free web hosting | website hosting | Business Hosting | Free Website Submission | shopping cart | Promoter Online | php hosting
affordable web hosting Pets web page hosting web hosting website hosting web hosting service web hosting web host
Writing a managed extension DLL

Writing a managed extension DLL

Writing a managed extension DLL

Writing a managed extension DLL (Dynamic-Linked Library) in Visual C++ IDE is a bit cumbersome, but once you set the right compiler and linker options, the DLL can be shared by any other project, including managed extension DLL so that you can incorporate the newly added functionalities of the extended VC++. This page will go through the whole process of writing a DLL.

A DLL is a library module which is a set of classes, interface, structure, methods, variables, etc that can be shared with other applications. There are a few rules in writing those DLL's.

  1. The "Configuration Type" must be set to Dynamic Library (.dll).
  2. All the function, class and variable declaration must carry __declspec(dllexport) prefix in the DLL headers. Likewise, __declspec(dllimport) prefix must be specified in the main project headers.
  3. The DLL must be in the same directory as the main project directory.
  4. The library path and the library file (.lib file) must be specified in the linker options.

1. Adding a New Managed DLL Project

First, select a DLL project. Go to File menu, select Add Project, and click New Project. Select the project type such as Managed Class Library.

File|Add Project|New Project

This DLL project will create a DLL file and a library file. Select the managed DLL project if you want to use the managed extensions.

2. Class/Function_Declaration: __declspec

The classes and function declaration in the DLL project headers must carry __declspec(dllexport) prefix.


   extern "C" __declspec(dllexport) int LoadXMLFile(char* fileName, CLabelsXML*);

The header files for the main project must carry __declspec(dllimport) prefix.


   extern "C" __declspec(dllimport) int LoadXMLFile(char* fileName, CLabelsXML*);

3. Copying the DLL files

Build the DLL project, and a library file (.lib) and a DLL file (.dll) will be created in the Release/Debug directory depending on the configuration. The DLL file must be copied to the main project directory. Here is a trick to do this without manually copying the file to the directory -- specify a shell command to copy the DLL file to the main project directory. Go to Custom Build Step section, and write the copy command. The Description entry is for the message that will be presented as the command is executed. The name of the DLL file should be specified in the Outputs directory.

Custom Build Step|General|Command Line

4. The Library File

The library file must be specified in the main project's linker option. First, set the library path. Go to the Linker option in the project property dialog. Under the General option, specify the DLL project's output directory in Additional Library Directories entry.

Linker|General|Additional Library Directories

Then, specify the library file. In the same Linker option, select Input option. Enter the name of the library file in the Additional Dependencies.

Linker|Input|Additional Dependencies

Once the DLL file is copied and the linker options are set, the project is all set to go.



Return to Home Page
Erica Asai
Last Modified: Mon Aug 08 09:35:32 2005