understanding of the creating dll in visual studio
I created some simple dll in visual studio, to begin to use it I read the following article:
To use the functionality from the class library in the console application
1) After you create a new console application, an empty program is created for you. The name for the source file is the same as the name that you chose for the project earlier. In this example, it is named MyExecRefsDll.cpp.
2) To use the math routines that were created in the dynamic link library, you must reference the library. To do this, select the MyExecRefsDll project in the Solution Explorer, then select References… from the Project menu. On the Property Pages dialog box, expand the Common Properties node, select Framework and References, and then select the Add New Reference… button. For more information about the References… dialog box, see Framework and References, Common Properties, Property Pages Dialog Box.
3) The Add Refere开发者_开发百科nce dialog box is displayed. This dialog lists all the libraries that you can reference. The Project tab lists all the projects in the current solution and any libraries they contain. On the Projects tab, select MathFuncsDll. Then click OK.
4) To reference the header files of the dynamic link library, you must modify the include directories path. To do this, on the Property Pages dialog box, expand the Configuration Properties node, expand the C/C++ node, and then select General. Next to Additional Include Directories, type the path of the location of the MathFuncsDll.h header file.
5) The executable does not load dynamic link libraries until runtime. You must tell the system where to locate MathFuncsDll.dll. You do so by using the PATH environment variable. To do this, on the Property Pages dialog box, expand the Configuration Properties node and select Debugging. Next to Environment, type the following: PATH=, where is replaced with the actual location of MathFuncsDll.dll. Click OK to save all the changes.*
I understand why we need to set a location for the header and dll (paragraphs 4 and 5), my question is why we need paragraphs 2 and 3 to reference the library? thanks in advance for any simple explanation
Step 2 and 3 describe steps to help create a managed project, one that uses the .NET framework. It is calling referencing an assembly, and is equivalent to linking in a library file for native apps. I take it you are creating a C++/CLI managed application?
From MSDN Framework and References, Common Properties, Property Pages Dialog Box "Use this property page to set references from a C++ project to .NET Framework assemblies, COM components, or external projects." Mostly for managed C++, i guess. References are used extensively in VB.NET/C# projects.
Steps 2/3 are needed to tell the linker where to find the compiled versions of the library so that it can link against them. You might find this useful: http://www.lurklurk.org/linkers/linkers.html
精彩评论