Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a C++ project so far developed as standalone executable into a DLL

(I'm using Microsoft Visual Studio 2010 on a Windows 7 64 bit machine)

I have developed a C++ program that is more of a library which became quite complex over time. It does right now work as a simple executeable, but I'd like to convert it into a DLL so the functionality can be accessed by other programs easily.

I'm not at all experienced in working with DLLs, but I want to avoid much additional work and code changes in the process.

I know that I can select the compile target to "DLL", but I have the feeling that alone won't do the job.

  • If I successfully compiled my project into a DLL file, how do I use the functions in it from an executable project?

  • Can I avoid using _dllexport and importing every function per-name?

  • How does one statically link a DLL, and what are the (dis)advantages of this?

like image 792
lamas Avatar asked May 10 '11 17:05

lamas


People also ask

How do you make a project a DLL in Visual Studio?

To create a DLL project in Visual Studio 2019On the menu bar, choose File > New > Project to open the Create a New Project dialog box. At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Library.


1 Answers

Honestly, I would take a look at the DLL export docs and pick whatever export method works best for you. In any case, you can simply reference exported functions by name from your client apps, as you would with a static library.

When you build the project as a DLL, the IDE will generate

  1. The DLL file for runtime and
  2. a LIB file containing exported function resolution information - that's the one you link against.

By definition, you cannot statically link a DLL (that's DYNAMIC link library) - instead, you link to a library that exports the functions from the DLL, and then the DLL loads at runtime, either automatically on process start or on demand. It's also possible to load the DLL completely on demand without any static linkage (see LoadLibraryEx etc).

like image 71
Steve Townsend Avatar answered Sep 23 '22 04:09

Steve Townsend