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
Who is Participating?
jkrConnect With a Mentor Commented:
See the articles under - especially ("Super Easy DLL") and ("Making DLLs easy to build and use") which are both compact and will give you a jump start on this issue.
ZoppoConnect With a Mentor Commented:
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: ("A Short Tutorial on Writing a WIN32 DLL") ("A Tutorial on creating DLLs with VC++") ("Creating And Using DLLs")
Forced accept.

EE Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.