• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 38699
  • Last Modified:

Create c++ dll in visual studio 2005

I need directions for creating a dynamic library in visual studio 2005, instead of a static library. The library should not necessary be conforming to the "COM" sta ndard the only demand is that I can use it in other c++ projects.

The dll should be compiled from some h- and cpp files. Then I expect a .lib file and a .dll file as output.

I have the following understanding of the issue.

To use the dll in another project, you references the h files and link against the .lib file, which basically just tells that we should fetch the dll at runtime and lookup the symbols in this file, but how to do this.

Some steps or examples will be appreciated. I have found


but it does not really help me

Thanks, Niels
  • 2
2 Solutions
See the articles under http://www.codeproject.com/dll/#Beginners - especially http://www.codeproject.com/dll/EasyDLL.asp ("Super Easy DLL") and http://www.codeproject.com/dll/DLL_EZ_Build_EZ_Usage.asp ("Making DLLs easy to build and use") which are both compact and will give you a jump start on this issue.
Hi nielsboldt,

if I understand you right you want to make a DLL which is implicitely linked, so you don't want to load/call the DLL at runtime using LoadLibrary/GetProcAddress.

To do so first step is to create a new Win32 project of type DLL - depending on your needs you can use MFC and/or ATL there. You need to take care that you use the same C-Runtime libraries (static or dynamically linked, single ot multithreaded) as in the calling application.

Next you need to export the functions/classes you want to use in the calling application. Therefor you can declare a macro in your header files somehow like this:

   #define MY_APP_API __declspec(dllexport)
   #define MY_APP_API __declspec(dllimport)

The MY_APP_EXPORT should be declared in the comile-settings 'Preprocessor->Preprocessor Definitions'

Then you can declare any function or class you want to export in header files like this:

void MY_APP_API foo();

class MY_APP_API MyClass

This way you can use the same header both in the DLL and the calling application - in the DLL the macro expands to __declspec(dllexport) which exports the declared functions/classes, in the calling application the macro expands to __declspec(dllimport) which declares the functions/classes in a way the compiler will generate import code.

Then you only have to link the .LIB which is built with the DLL to the application in order to use the exported functions/classes in the application.

I hope that helps,

Also of interest:

http://www.coopknow.com/papers.asp?paper=5 ("A Short Tutorial on Writing a WIN32 DLL")
http://www.logix4u.net/dll_tutorial1.htm ("A Tutorial on creating DLLs with VC++")
http://www.flipcode.com/articles/article_creatingdlls.shtml ("Creating And Using DLLs")
Forced accept.

EE Admin

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now