Saturday, July 25, 2020

understanding of Visual C++ header files and resource file

TN028: Context-sensitive help support

authoritive information on context-sensitive help support for C++ application.

  1. TN033: DLL Version of MFC
  2. TN028: Context-Sensitive Help Support
  3. CWinApp Class
  4. Understanding Context-Sensitive Help
  5. CWinApp::HtmlHelp function is the major method to use HTML help:

    definition: Call this member function to invoke the HTMLHelp application.

    virtual void HtmlHelp( DWORD_PTR dwData, UINT nCmd = 0x000F);

  6. HtmlHelpA function
  7. this link lists all items on htmlhelp.h information. can review more times.

  8. HH_HELP_CONTEXT command
  9. Displays a help topic based on a mapped topic ID.

    If a window type is not specified, a default window type is used. If the window type or default window type is open, the help topic replaces the current topic in the window.


Saturday, July 11, 2020

how to distribute C runtime library?

I need to remove extra feature I installed on SQL 2019. it is too big.

  1. Dependency Walker 2.2
  2. How to Distribute C run-time (CRT) Libraries with Your Application
  3. Introducing the Universal CRT
  4. How to Enforce C++ compiler to use specific CRT version?
  5. How to: Sign application and deployment manifests
  6. Upgrade your code to the Universal CRT
  7. Binding to the most recent Visual Studio Libraries
  8. Go to the folder containing the executable we’ve just build and use the following command to extract the manifest from our executable:

    mt.exe -inputresource:bindingtest.exe -out:manifest.txt

    where bindingtest.exe is the name of your executable. The file manifest.txt will contain the exported manifest.

  9. How to distribute C run-time (CRT) Libraries
  10. TN033: DLL Version of MFC
  11. Shipping an application that uses the shared library requires that you ship the MFCxx.DLL (and others) library with your program. MFCxx.DLL is freely redistributable like many DLLs, but you still must install the DLL in your SETUP program. In addition, you must ship the MSVCRTxx.DLL, which contains the C-runtime library which is used both by your program and the MFC DLLs themselves.

  12. Manifest Generation in Visual Studio
  13. Generation of a manifest file for a particular project can be controlled in the project Property Pages dialog. On the Configuration Properties tab, click Linker, then Manifest File, then Generate Manifest. By default the project properties of new projects are set to generate a manifest file. However it is possible to disable generation of the manifest for a project using the Generate Manifest property of the project. When this property is set to Yes, the manifest for this project is generated. Otherwise the linker ignores assembly information when resolving dependencies of the application code, and does not generate the manifest.

  14. Manifest Generation at the Command Line 11/04/2016 2 minutes to read
  15. Mt.exe :: manifest tool
  16. on Visual Studio 2017 enterprise location of mfc140u.dll and mfcm140u.dll:

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Redist\MSVC\14.10.25017\x86\Microsoft.VC150.MFC

    mfc140u.dll and mfcm140u.dll

    under C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x86\Microsoft.VC140.CRT

    1. vcruntime140.dll
    2. vccorlib140.dll
    3. msvcp140.dll
    4. concrt140.dll

    under C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x86\Microsoft.VC140.MFC

    1. mfc140u.dll
    2. mfcm140u.dll

  17. How to select the version of the VC 2008 DLLs the application should be linked to?
  18. How to select against which version of the Visual C++ libraries the application is compiled?
  19. Обсуждение: Standalone Windows Installation
  20. setup cannot find the file office.en-us\microsoft.vc80.crt.manifest
  21. VCRUNTIME140.dll missing
  22. questionI have a problem when trying to install apache 2.4 on my windows 10. It always shows the error that VCRUNTIME140.dll is missing. I have checked other threads and found out that installing the 2015 Visual c++ Redistributables x64/x86 always solves the problem but I have both installed and I still have this problem. Are there any other solutions?


Hello World app building errors

I build a simple application from the book in Allan Feuer's first example. I got Hello World app building errors. then I research these errors and the leaned many good configurations. documented here for future reference. it touched a lot of configurations in Visual Studio on DLL linking though this Hello Word does not use MFC DLL.

I documented all my research for future reference on these configurations of Visual Studio C++ project.

These two action items are very important:

Action 1. configuration property->linker->system->sub system: Windows

Action 2. configuration property->C/C++ -> code generation -> runtime library -> MT , MTD etc..

the short summary would be:

If you are using “Use of MFC -> Use MFC in a Static Library” then you must use /MT (release) or /MTd (debug) CRT library.

If you are using “Use of MFC -> Use MFC in a Shared DLL” then you must use /MD (release) or /MDd (debug) CRT library.

The following topic discusses the various .lib files that comprise the C run-time libraries as well as their associated compiler options and preprocessor directives.

The C Run-time Library (CRT) is the part of the C++ Standard Library that incorporates the ISO C99 standard library. The Visual C++ libraries that implement the CRT support native code development, and both mixed native and managed code. All versions of the CRT support multi-threaded development. Most of the libraries support both static linking, to link the library directly into your code, or dynamic linking to let your code use common DLL files.

Starting in Visual Studio 2015, the CRT has been refactored into new binaries. The Universal CRT (UCRT) contains the functions and globals exported by the standard C99 CRT library. The UCRT is now a Windows component, and ships as part of Windows 10. The static library, DLL import library, and header files for the UCRT are now found in the Windows 10 SDK. When you install Visual C++, Visual Studio setup installs the subset of the Windows 10 SDK required to use the UCRT. You can use the UCRT on any version of Windows supported by Visual Studio 2015 and later versions. You can redistribute it using vcredist for supported versions of Windows other than Windows 10. For more information, see Redistributing Visual C++ Files.

  • CRT Library Features
  • warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs
  • one new configuration I paid attention:

    2) C/C++ -> Code Generation -> Basic Runtime Checks as Both (/RTC1, equiv. to /RTCsu)

  • Warning lnk4098: defaultlib "msvcrt" conflicts with use of other libs; Use/nodefaultlib
  • There is a table to show all kinds of combinations of Runtime library to be used.

    it seems like the above post is translated from the following article in Chinese:

  • warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
  • warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
  • warning LNK4098: 默认库“MSVCRT”与其他库的使用冲突;使用 /NODEFAULTLIB:library问题解决方法
  • Guide - How to avoid C/C++ runtime on Windows
  • Avoiding the Visual C++ Runtime Library
  • solution is:

    Link Warning Solutions: Engineering Attributes - > Linker - > Input - > ignore specific default liries by adding the omitted item msvcrt.lib.


    I got following errors:

    Error (active) E0035 #error directive: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] HelloWin C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\atlmfc\include\afx.h 24

    1. error Please #define _AFXDLL or do not use /MD[d] occurs even after making changes in Project Properties
    2. if I use MFC static link library, I got this error after recompiling it:

      Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) HelloWin C:\Demo\HelloWin\HelloWin\msvcrtd.lib(exe_main.obj) 1

    3. /MD, /MT, /LD (Use Run-Time Library)
    4. Error LNK2019 unresolved external symbol _main referenced in function “int __cdecl invoke_main(void)” (?invoke_main@@YAHXZ)
    5. I made this change:

      Check project configuration. Linker->System->SubSystem should be Windows.

    6. What is an undefined reference/unresolved external symbol error and how do I fix it?
    7. #error Please use the /MD switch for _AFXDLL builds
    8. Settings for CRT linking and MFC linking must be coherent. So, actually, there are two possible answers at this question:

      step 1. Use /MT (Properties -> C/C++ -> Code Generation) and static MFC (Properties -> General -> Use of MFC)

      step 2. Use /MD (Properties -> C/C++ -> Code Generation) and shared MFC (Properties -> General -> Use of MFC)

    9. Error C1189 #error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] Hello2 c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\atlmfc\include\afx.h 24

      based on above descriptions, I selected MFC shared DLL and C/C++ -> code generation -> runtime library -> /MD

      Warning LNK4098 defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library Hello2 C:\Demo\Hello2\Hello2\LINK 1

    10. How to use /NODEFAULTLIBS option in compilation?
    11. Resolving LNK4098: defaultlib 'MSVCRT' conflicts with
    12. Unresolved external symbols while moving C++ MFC-based application to VS2015 from VS2013

    Thursday, July 9, 2020

    how to create and use/include a DLL in Visual C++ and deployment?

    how to create DLL in Visual C++?

    1. Walkthrough: Create and use your own Dynamic Link Library (C++)
    2. Is there a Visual Studio Project Configuration Macro which defines DEBUG or RELEASE regardless of the Project Configuration Name?
    3. Deployment in Visual C++
    4. Universal CRT deployment
    5. How do I setup visual studio to register some #defines globally?
    6. Identify current configuration using preprocessor directives on visual studio?
    7. “Debug only” code that should run only when “turned on”
    8. Dynamic-Link Library Search Order
    9. Working with Import Libraries and Export Files
    10. Link an executable to a DLL
    11. DLL Frequently Asked Questions
    12. it includes two steps:

      DLL produce:1) Create a DLL project in Visual Studio. 2)Add exported functions and variables to the DLL.

      consumer: 1)Create a console app project in Visual Studio. 2)Use the functions and variables imported from the DLL in the console app. 3)Run the completed app.

      in this DLL demo, I did not create the same project as this post, so macro MATHLIBRARY_EXPORTS is not defined as it specifies. so I created a macro in the C/C++ preprocessor -> define my own MATHLIBRARY_EXPORTS.

    13. Link an executable to a DLL
    14. An executable file links to (or loads) a DLL in one of two ways:

      1. Implicit linking, where the operating system loads the DLL at the same time as the executable that uses it. The client executable calls the exported functions of the DLL the same way as if the functions were statically linked and contained within the executable. Implicit linking is sometimes referred to as static load or load-time dynamic linking.
      2. Explicit linking, where the operating system loads the DLL on demand at runtime. An executable that uses a DLL by explicit linking must explicitly load and unload the DLL. It must also set up a function pointer to access each function it uses from the DLL. Unlike calls to functions in a statically linked library or an implicitly linked DLL, the client executable must call the exported functions in an explicitly linked DLL through function pointers. Explicit linking is sometimes referred to as dynamic load or run-time dynamic linking.

      An executable can use either linking method to link to the same DLL. Furthermore, these methods aren't mutually exclusive; one executable may implicitly link to a DLL, and another might attach to it explicitly.

      Implicit Linking, what is it? and when it happens?

      Implicit linking occurs when an application's code calls an exported DLL function. When the source code for the calling executable is compiled or assembled, the DLL function call generates an external function reference in the object code. To resolve this external reference, the application must link with the import library (.lib file) provided by the maker of the DLL.

      The import library only contains code to load the DLL and to implement calls to functions in the DLL. Finding an external function in an import library informs the linker that the code for that function is in a DLL. To resolve external references to DLLs, the linker simply adds information to the executable file that tells the system where to find the DLL code when the process starts up.

      When the system starts a program that contains dynamically linked references, it uses the information in the program's executable file to locate the required DLLs. If it can't locate the DLL, the system terminates the process, and displays a dialog box that reports the error. Otherwise, the system maps the DLL modules into the process address space.

      If any of the DLLs has an entry-point function for initialization and termination code such as DllMain, the operating system calls the function. One of the parameters passed to the entry-point function specifies a code that indicates the DLL is attaching to the process. If the entry-point function doesn't return TRUE, the system terminates the process and reports the error.

      Finally, the system modifies the executable code of the process to provide starting addresses for the DLL functions. Like the rest of a program's code, the loader maps DLL code into the address space of the process when the process starts up. The operating system loads it into memory only when needed. As a result, the PRELOAD and LOADONCALL code attributes used by .def files to control loading in previous versions of Windows no longer have meaning.

      How to use implicit linking?

      To use a DLL by implicit linking, client executables must obtain these files from the provider of the DLL:

      • One or more header files (.h files) that contain the declarations of the exported data, functions, and C++ classes in the DLL. The classes, functions, and data exported by the DLL must all be marked __declspec(dllimport) in the header file. For more information, see dllexport, dllimport.
      • An import library to link into your executable. The linker creates the import library when the DLL is built. For more information, see LIB files as linker input.
      • The actual DLL file.

      To use the data, functions, and classes in a DLL by implicit linking, any client source file must include the header files that declare them. From a coding perspective, calls to the exported functions are just like any other function call.

      To build the client executable file, you must link with the DLL's import library. If you use an external makefile or build system, specify the import library together with the other object files or libraries that you link.

      The operating system must be able to locate the DLL file when it loads the calling executable. That means you must either deploy or verify the existence of the DLL when you install your application.

    15. Kinds of DLLs
    16. it explains all kinds of DLLs clearly.

    17. Determining Which DLLs to Redistribute
    18. it tells which DLL to distribute.

    19. Visual Studio 2017 compiles in 32bit on 64 bit system?
    20. Build 32-bit DLL on 64-bit Windows® Platform Using MSVC Toolchain
    21. Back to Basics: 32-bit and 64-bit confusion around x86 and x64 and the .NET Framework and CLR
    22. How to create a 64-bit C DLL with MSVC 2017 and IDL 8.7 for Windows 10
    23. 4.5 Compiling in Windows with MSVC
    24. How do I use a third-party DLL file in Visual Studio C++?
    25. Link an executable to a DLL
    26. C++ toolkit installation on Windows
    27. How to create and use DLL (Dynamic Link Library) in (C+
    28. Configuring Your Project's Build Settings
    29. C++ - Windows - Creating a dynamic-link library (DLL)
    30. Dynamic-link library
    31. Projects in Visual C++ 2010 – Part 1: Creating a DLL project
    32. Module 16: C++, MFC & Dynamic Link Libraries - DLL 1
    33. Module 16a: Windows Dynamic Link Libraries - DLL 2
    34. Module 16b: Windows Dynamic Link Libraries - DLL 3
    35. Module 16c: Windows Dynamic Link Libraries - DLL 4
    36. MODULE BB DYNAMIC LINK LIBRARY - DLL Part 1: STORY
    37. MODULE CC DYNAMIC LINK LIBRARY - DLL Part 2: PROGRAM EXAMPLES
    38. MODULE CC1 DYNAMIC LINK LIBRARY - DLL Part 3: PROGRAM EXAMPLES
    39. Creating and Using a Dynamic Link Library(DLL) in VC++
    40. it has three related papers in the bottom sections.

    41. Setting up the Boost C++ library

    Sunday, July 5, 2020

    VC include lib files

    1. Set compiler and build properties:: on Microsoft.com
    2. this page is a summary of all settings on project property pages. especially VC++ directories. from this page I can also jump into other related pages too. so it is a good gate.

      In the IDE, all information that is needed to build a project is exposed as properties. This information includes the application name, extension (such as DLL, LIB, EXE), compiler options, linker options, debugger settings, custom build steps, and many other things. Typically, you use property pages to view and modify these properties. To access the property pages, choose Project > projectname Properties from the main menu, or right-click on the project node in Solution Explorer and choose Properties.

      C++ compiler and linker options are located under the C/C++ and Linker nodes in the left pane under Configuration Properties. These translate directly to command-line options that will be passed to the compiler. To read documentation about a specific option, select the option in the center pane and press F1. Or, you can browse documentation for all the options at MSVC Compiler Options and MSVC Linker Options.

      The Property Pages dialog box shows only the property pages that are relevant to the current project. For example, if the project does not have an .idl file, the MIDL property page is not displayed. For more information about the setting on each property pages, see Property Pages (C++).

      VC++ Directories Property Page (Windows) is a good place to review all VC++ related configurations.

      Directory and path values

      MSBuild supports the use of compile-time constants called "macros" for certain string values include directories and paths. These are exposed in the property pages, where you can refer to and modify them by using the Property Editor.

      The following illustration shows the property pages for a Visual Studio C++ project. In the left pane, the VC++ Directories rule is selected, and the right pane lists the properties that are associated with that rule. The $(...) values are called macros. A macro is a compile-time constant that can refer to a value that is defined by Visual Studio or the MSBuild system, or to a user-defined value. By using macros instead of hard-coded values such as directory paths, you can more easily share property settings between machines and between versions of Visual Studio, and you can better ensure that your project settings participate correctly in property inheritance.

    3. Consuming libraries and components inVS 2019
    4. If the static library is not part of the solution:

      step 1. Right-click on the application project node in Solution Explorer and then choose Properties.

      step 2. In the VC++ Directories property page, add the path to the directory where the .lib file is located in Library Paths and add the path to the library header file(s) in Include Directories.

      step 3. In the Linker > Input property page, add the name of the .lib file to Additional Dependencies.

    5. How to add additional libraries to Visual Studio project?
    6. 3 steps work here too.

      For Visual Studio you'll want to right click on your project in the solution explorer and then click on Properties.

      Next open Configuration Properties and then Linker. Now you want to add the folder you have the Allegro libraries in to Additional Library Directories,

      Linker -> Input you'll add the actual library files under Additional Dependencies.

      For the Header Files you'll also want to include their directories under C/C++ -> Additional Include Directories.

      If there is a dll have a copy of it in your main project folder, and done.

    7. How to include libraries in Visual Studio 2012? ::on tutorialspoint.com
    8. it also has 3 steps, but slightly different than the bottom 3 steps.

      To add libraries in Visual Studio 2012, there are two different methods. The first one is manual method. The second one is adding libraries from code. Let us see the manual method first.

      To add some library, we have to follow these five steps − Add the #include statements necessary files with proper declarations. For example − #include “library.h”

      Add the include directory for the compiler look up; Go to the Configuration Properties/VC++ Directories/Include Directories Then click and edit, and add new entry

      Add one library directory for *.lib files: Go to project (on top bar) -> properties -> Configuration Properties -> VC++ Directories -> Library Directories, then click and edit, and add new entry.

      Link the lib’s *.lib files − Go to Configuration properties -> linker -> input -> Additional Dependencies

      Place *.dll files either − In the directory you will be opening final executable from or into Windows/System32

      Now we will see how to add libraries using code − Use the compiler directives #pragma − #pragma comment(lib, “library.lib”)

    9. How to include libraries in Visual Studio 2012? on stackoverflow.com
    10. this title is the same as above, but this is on stackoverflow.com.

    11. Adding a .lib file to a project in Visual Studio 2015 [duplicate]
    12. this post confirmed the linker->input->type .lib file name is necessary.

    13. .Lib Files as Linker Input
    14. LINK accepts COFF standard libraries and COFF import libraries, both of which usually have the extension .lib. Standard libraries contain objects and are created by the LIB tool. Import libraries contain information about exports in other programs and are created either by LINK when it builds a program that contains exports or by the LIB tool

      To add .lib files as linker input in the development environment, do these steps:

      step 1: Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

      step 2: Choose the Input property page in the Linker folder.

      step 3: Modify the Additional Dependencies property to add the .lib files.

    15. how to link with .a lib file in visual studio:: on social community on Microsoft.com
    16. To add .lib files as linker input in the development environment

      step 1: Open the project's Property Pages dialog box. For details, see Working with Project Properties.

      step 2: Choose the Input property page in the Linker folder.

      step 3: Modify the Additional Dependencies property to add the .lib files.

    17. A.2 — Using libraries with Visual Studio
    18. 3 steps still work here:

    19. Configuring Visual Studio for C/C++ Projects
    20. 3 steps (bottom) works here.

    21. Youtube::How-To Set Up Includes, Linkers, Libraries on Visual Studio 2017 C++
    22. Visual C++ 6.0::1. Set headers and libraries path
    23. C++ Programming/Compiler/Linker/Libraries/Configuring Visual Studio
    24. summary: it has 3 steps:

      step 1: project settings->C/C++ => General ==> additional include libraries. this is to set up the include directory. This is the directory that contains the header files (.h/hpp), which describes the library interface

      step 2: project settings->Linker -> General ->Additional Library directories. this is to set up the library directory. This is the directory that contains the pre-compiled library files (.lib)

      step 3:project settings->Linker -> Input ->Additional Dependencies. this is to enter library filenames in additional dependencies for the libraries to use. such as libboost_regext-VC71-mt.lib

    25. Setting up Glut / FreeImage in Microsoft Visual Studio
    26. C++ Linking to External Library
    27. it seems like it missed one step of the 3 steps.

    28. Microsoft Visual C++ Static and Dynamic Libraries
    29. Walkthrough: Create and use a static library
    30. we can build the project to target in two forms: one is to target platform: cross all platform; another platform is to target to win32

      in this example, because we target platform :cross all platform. so we configure include library in C/C++ category as below:

      Select the Configuration Properties > C/C++ > General property page. In the Additional Include Directories property, specify the path of the MathLibrary directory, or browse for it. here I put lib and header files respectively into C:\Temp\Include and C:\Temp\Library folders.

      Linker-> General -> Additional Library Directories: enter C:\Temp\library

      Linker-> Input -> Additional Dependencies: enter MathLibrary.lib through drop down menu->edit

      include header file into source code as: #include "MathLibrary.h"

      compile this project and everything works perfectly.

      I repeated above steps to build this MAthClient project to target Active Win32 project and set up property in VC++ directories-> include directories: here I enter C:\Temp\include by drop down->edit menu.

      I set up linker->General and linker->input respectively as before.

      compile the project. it works successfully.