Creating a Dll file

2019-06-26 07:40发布

问题:

I am about to create a dll project with Visual Studio.

What is its mechanism later?

Does that generate at the end a dll file which can be used later in some other projects?

回答1:

Exactly. Use dll functions exports and import and make two seperate projects: application and dll. That's it!



回答2:

VS will generate two files for you: A .lib and a .dll.

In principle, the .dll is all that is needed. You can just call LoadLibrary on the file and retrieve any exported function directly from the .dll file. The problem here is that the compiler will not know which functions the dll provides, so you will have to do a GetProcAddress call for each function that you want to use.

Since this is highly inconvenient, VS also generates the .lib file, which takes care of this whole hassle for you. Just statically link your executable against the .lib and it will take care of the whole dll loading mess for you at runtime. Then just include both the dll and the exe (but not the lib) in your installation package that you ship to your customers.



回答3:

Yes, once it compiles, then in another project you can add a reference to the project or to the dll (browse option).



回答4:

Does that generate at the end a dll file which can be used later in some other projects?

yes, for your project a dll will be created and put into Debug or/and Release build folders. You can then reference this library in other projects (i.e. in MS Excel you can access DLL functions and commands in VBA by using the Declare statement)