0

I have managed to successfully create a C++ executable that references a C++ DLL using this tutorial: http://programmingexamples.wikidot.com/blog:1.

I am a .NET Developer. Using .NET you simply add a reference to the DLL from the console project. Using C++, you have to perform three steps (all in step four contained in the link). My questions are:

1) Why do you have to add the LIB as an Additional Dependency (step 4, part 1).  I believe it acts as a stub for the DLL, which is the skeleton.  This is not needed using .NET.
2) Step 4 (part 2) asks you to move the DLL to the same directory as the calling program.  Do you8 have to do this for every calling
program? I assume that if you add a reference to the DLL
(Properties/Common Properties/Add New Reference) that this step is not
needed?
3) Step 4(part 3) states that you must specify the location of the header files.  Why is this step needed if the header files are part of the DLL.  Is this because they are precompiled?

I understand that C++ and Visual Basic.NET/C#.NET are two completely different languages, however I do not yet understand why these additional steps are needed.

w0051977
  • 15,099
  • 32
  • 152
  • 329

1 Answers1

0
  1. You can read about lib here What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?

"You don't need a .lib file to use a dynamic library, but without one you cannot treat functions from the DLL as normal functions in your code. Instead you must manually call LoadLibrary to load the DLL (and FreeLibrary when you're done), and GetProcAddress to obtain the address of the function or data item in the DLL. You must then cast the returned address to an appropriate pointer-to-function in order to use it."

  1. You don't have to move the dll's to the executable directory. You can assign it to windows path http://www.computerhope.com/issues/ch000549.htm - that is where the dll's will be sought for.

  2. Header files are something like interface. They contain declarations of the functions. Why have header files and .cpp files in C++? "The header file is thus necessary, because the C++ compiler is unable to search for symbol declarations alone, and thus, you must help it by including those declarations."

Community
  • 1
  • 1
Mikołaj Mularczyk
  • 959
  • 12
  • 20