If you have a DLL that you want to distribute, and you do not want to associate your subscribers with a specific version with C-Runtime, do one of the following:
I. Link the DLL to the static version of the C-Runtime library. On the Visual Studio project properties page, select the tab Configuration Properties → C / C ++ → Code Generation. This is an option to select "Runtime Library". Select Multithreading or Multithreaded Debugging instead of DLL versions. (Conditional command line value is / MT or / MTd)
There are several different disadvantages to this approach:
a. If Microsoft ever releases a CRT security patch, your submitted components may be vulnerable until you recompile and reinstall your binary.
b. The heap pointers allocated by "malloc" or "new" in the DLL cannot be "free" or "delete" d EXE or other binary code. Otherwise you will collapse. The same is true for FILE descriptors created by fopen. You cannot invoke fopen in a DLL and expect the exe to depend on it. Again, if you do. You will need to create an interface for your DLL to be resistant to all these problems. For starters, a function that returns an instance in std :: string is likely to be a problem. Provide the functions exported by your DLL to handle the release of resources as needed.
Other parameters:
II. Ship without c-runtime depedency. This is a little trickier. First you need to remove all calls from the CRT from your code, provide some stub functions to link the DLL, and provide a link to the "no by default" link. It can be done.
III. C ++ classes can be exported from DLLs using COM interface pointers. You still have to solve the problems described in 1a above, but ATL classes are a great way to get rid of COM overhead.
source share