Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS VC++ how to build DLL without requiring vc redist

I'm trying to build a simple .Net wrapper around some basic C++ code.

The C++ code does not rely on anything in the vcredist dlls, so I'm wondering if I can setup my project, so it doesn't require those dlls to work ?

I'd hate to have my users download and run vcredist, just for a simple DLL to work.

like image 404
Steffen Avatar asked Jul 19 '09 09:07

Steffen


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.

Can I use a DLL without lib?

The only way to access a bare DLL without a . lib file is to load the DLL explicitly with LoadLibrary() , get pointers to the exported functions you want to access with GetProcAddress() , and then cast those pointers to the proper function signature.

Is DllMain required?

DllMain is not mandatory. If you have some initialization code required to run when loading the dll, you should create a DllMain function, and treat the initialization there. Otherwise it's not required.

What is _DllMainCRTStartup?

The _DllMainCRTStartup function performs essential tasks such as stack buffer security set up, C run-time library (CRT) initialization and termination, and calls to constructors and destructors for static and global objects.

How do I create a resource only DLL in Visual Studio?

Create a resource-only DLL To create a resource-only DLL, you create a new Windows DLL (non-MFC) project, and add your resources to the project: Select Windows Desktop Wizard in the New Project dialog box and choose Next. In the Configure your new project page, enter the project and solution names, and choose Create.

Where are redistributable DLLs installed in Visual Studio?

The individual redistributable DLLs are also included in your installation of Visual Studio. By default, they are installed in the Visual Studio installation directory in the VCRedist[&MSVC&] version folder. The version numbers may represent different minor build numbers of a single common set of redistributable files.

Does Visual C++ 2010 require Win32 DLLs?

You will see it if you will try to run the project, the creation of the Visual C++ 2010, on a freshly installed Windows: If you will open your EXE in DependencyWalker, you will see it requires one or few DLLs but Win32 DLLs ( user32, kernel32, etc)!

Is it possible to use static linking with VC++ Redist?

Build and debug it! Now your EXE weighs a few hundred KBs more than before, but, it is fully standalone! Unfortunately, you can use static linking only for VC++ Redist and other unmanaged libs, but can't do it with managed libs, can't create CLR project not requiring .NET.


1 Answers

You need to link your DLL with the "Use the CRT as a static library" option:

Project properties / Configuration / C/C++ / Code Generation / Runtime library / Multithreaded (ie. not any of the "DLL" options).

like image 186
RichieHindle Avatar answered Nov 15 '22 08:11

RichieHindle