Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have these cpp files and a lot of header files for c++ libraries, so i can reference them in a VS Projects, but everytime i have to add all of files (almost 50) to start with, Isnt there any easy way to compile all of headers of c++ in a .dll and reference only one file.
Posted
Updated 2-Sep-14 1:14am
v2

Revised answer.

If you want to create a Win32 DLL and have the .h and .cpp files you should be able to do it using this walkthrough:

Walkthrough: Creating and Using a Dynamic Link Library (C++[^]

If you then want to access the methods in this Win32 unmanaged DLL from .Net managed code (c# or VB), you need to use Platform Invoke (PInvoke).

This tutorial gives you a starting point:
Platform Invoke Tutorial[^]

This web site gives you examples of standard Win32 methods and their .Net signatures.
It can be helpful as a reference.
http://pinvoke.net/[^]


Sorry for the misunderstanding, but the question was not crystal clear to me.

==========================================================

The answer below is for including .h and .lib files into a project, not creating a DLL.

If you only have header files and compiled lib files, you can put all your header files in one directory, Include, and the lib files in another, Library.

Then you can either add these directories to your project or to VS IDE (if you use them all the time)

1. Add to the project
Open the properties for the project.
1.a. Go to Configuration Properties -> C/C++ -> General
Add your Include directory to the property 'Additional Include Directories'.
1.b. Go to Configuration Properties -> Linker -> Input
Add your Library directory to the property 'Additional Dependencies'.


2. Add to Visual Studio

Go menu item Tools -> Options -> Projects and Solutions -> VC++ Directories and add your directories there.
This seems only to work prior to VS 2005, though.
 
Share this answer
 
v3
Comments
psychic6000 2-Sep-14 5:54am    
thanks, i actually mean to ask, "if there is any way to compile these files (header, and libraries) in to dll files," so i can even reference it with visual basic or c sharp may be...
George Jonsson 2-Sep-14 6:10am    
That is a different question.
You could create a managed C++ project and create a new set of methods to export as .Net methods with .Net types.
Internally you then use the header and lib files.
This you only do once, so it might be worth the extra work if you use these files a lot.
psychic6000 2-Sep-14 6:19am    
ok, that can be a long way, any short cut to just add it somewhere and click the compile button and get your .dll libraries...? thank you!
Yes, that is what a library is all about. You can either create a static library (.olb) or a dynamic load library (.dll). When using a static library, the linker tries to resolve all external references by including the actual code for the functions that are needed. Dynamic link libraries always contain all the code that was put together when building them. They are attached to your process at load time, which keeps your .exe file snug and small.

Which one of the libraries you want to use depends on your requirements. DLLs need to be distributed and installed together with your .exe file. But they have the advantage of being possibly shared between several of your applications and you can later exchange them for bug fixing or extending the functionality.

A static library is somewhat easier to handle and will finally be incorporated into the .exe file of your application.
 
Share this answer
 
Comments
psychic6000 2-Sep-14 6:18am    
you are right, and i get you, but you are telling me the advantages of dll and how those work, which i already know, my question is the way to make dll files from .h or .cpp files. thank you!
nv3 2-Sep-14 7:35am    
There is a project type for that in Visual Studio. Just create a project of that type and add your .cpp and .h file to it. Go through the properties of the project and adjust them to your needs, e.g. the default load address. Then build the project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900