• 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

http://msdn2.microsoft.com/en-us/library/ms235636(VS.80).aspx

but it does not really help me

Thanks, Niels
0
nielsboldt
Asked:
nielsboldt
  • 2
2 Solutions
 
jkrCommented:
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.
0
 
ZoppoCommented:
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:

 #ifdef MY_APP_EXPORT
   #define MY_APP_API __declspec(dllexport)
 #else
   #define MY_APP_API __declspec(dllimport)
 #endif

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,

ZOPPO
0
 
jkrCommented:
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")
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

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