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.
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.
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.
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.
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.
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.
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.
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)!
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With