Saturday, January 27, 2018

Visual Studio 2008 setup

walk through to create DLL in visual studio 2008 ,2010, 2015, and 2017

    I tested and summarized my note on creating DLL in Visual Studio different versions.

  1. Walkthrough: Creating and Using a Dynamic Link Library (C++)- you can find Visual Studio 2008
  2. for Visual Studio 2008, when you use DLL, just do steps:

    1. reference DLL assembly: Project Properties-> Common Properties ->Reference -> Add New reference:
    2. project Properties -> Configuration Properties->C/C++ node->add additional include directories, specify where .h file is located
    3. update PATH environment info to tell where DLL is located because executable does not load DLL until runtime. so you need to tell where to load DLL file: Project property page-> configuration properties->Debugging:: Environment, type path such as PATH=. here I used $(TargetDir)


  3. Walkthrough: Creating and Using a Dynamic Link Library (C++)
  4. in Visual Studio 2015, we have another way to add reference this DLL. it is the same as regular .NET assembly reference. need to test it out on Visual Studio 2017 sometime.

    first create a client Windows console application.

    To use the functionality from the class library in the app

    1. When the Win32 Application Wizard finishes, a minimal console application project is created for you. The name for the main source file is the same as the project name that you chose earlier. In this example, it is named MathClient.cpp.
    2. To use the math routines that you created in the DLL, you must reference the DLL in your app. To do this, under the MathClient project in Solution Explorer, select the References item. On the menu bar, choose Project, Add Reference.
    3. The Add Reference dialog box lists the libraries that you can reference. The Projects tab lists the projects in the current solution and any libraries that they contain. On the Projects tab, select the check box next to MathLibrary, and then choose the OK button.
    4. You need the definitions in the MathLibrary.h file to call the DLLs functions from your app. You could copy the header file into your client app project, but that might lead to changes in one copy that are not reflected in the other. To avoid this issue when you reference the header files of the DLL, you can change the included directories path in your project to include the original header.

      To do this, open the Property Pages dialog box for the MathClient project. In the left pane, expand Configuration Properties, C/C++ node, and then select General. In the center pane, select the drop-down control next to the Additional Include Directories edit box, and then choose . Select the top pane of the Additional Include Directories dialog box to enable an edit control. In the edit control, specify the path to the location of the MathLibrary.h header file. Because typing the complete path may be difficult, you can use the browse control (...) at the end of the edit box to bring up a Select Directory dialog box. In the dialog, navigate up one folder level to the MathLibraryAndClient folder, then select the MathLibrary folder, and then choose the Select Folder button. Once you've entered the path to the header file in the Additional Include Directories dialog box, choose the OK button to go back to the Property Pages dialog box, and then choose the OK button to save your changes.

    5. You can now include the MathLibrary.h file and use the Functions class in your client application. Replace the contents of MathClient.cpp by using the following code:
    6. NOTE In older versions of Visual Studio, references are added to your project in a different way. Select the MathClient project in Solution Explorer, and then on the menu bar, choose Project, References. In the Property Pages dialog box, expand the Common Properties node, select Framework and References, and then choose the Add New Reference button. For more information about the References dialog box, see Adding references.


  5. Walk through: Create and use your own Dynamic Link Library (C++)::Visual Studio 2017
  6. In visual Studio 2017, when we create DLL prpoject, we have more settings(but I tried in Visual Studio 2008 with the same steps):

    1. generate windows 32 console application - > select DLL -> leave checked precompiled headers.
    2. make sure MATHLIBRARY_EXPORTS is set up in preprocessor:Project-> properties->Configuration Properties -> C/C++-> preprocessor definitions. if it is MathLibrary_EXPORT, you need to edit it into MATHLIBRARY_EXPORTS.
      when you edit this field, please make sure to do: Property Pages dialog, change the Configuration drop-down to All Configurations
    3. inside source folder, dllmain.cpp is automatically generated. no touch.
    4. build this project, it will succeed.

    in visual Studio 2017, when we create a console application to use DLL prpoject, we have more settings:

    1. create a windows 32 console application with precompiled header file checked.
    2. to call the functions MathLibrary.dll, your project needs to include MathLibrary.h. you can either copy this file into your client app directory, or set up Additional Include Directories path in your client app project to include the path to original DLL header .
      Property Pages-> configuration drop down, select ALL Configurations if not already selected. then go to Configuration Properties-> C/C++ ->General-> select Additional Include Directories edit box.
      in my project settings, I used ..\MathLibrary
    3. At this point, your MathClient can be compiled, but not linked. the linker must be able to find the MathLibrary.lib file to link successfully. you can either copy MathLibrary.lib to your Mathclient app project, or you can point it to MathLibrary directory (in fact it is Debug folder).
      MathClient project->Property Pages ->Configuration drop down, please select All Configuration if it is not already selected. ->Configuration Properties-> Linker->Input->Additional Dependencies->Edit, type MathLibrary.lib .
      It specifies additional items to add to the link command line. (i.e.,kernel32.lib)
    4. in the left pane, select Configuration Properties->Linker->General->Additional Library Directories->Edit
      please enter ..\MathLibrary\$(IntDir)
      this will tell where to find MathLibrary.lib file.
      in Visual Studio 2017, it is written as: this Additional Library Directories allows user to override the environmental library path. (/LIBPATH: folder)
      in Visual Studio 2008, it is written as: specifies one or more additional paths to search for libraries; configuration specific; use semicolon delimited list if more than one. (/LIBPATH:[dir]
    5. Build MathClient project. it will succeed.
    6. post-build event seems like not necessary.


  7. Projects in Visual C++ 2010 – Part 1: Creating a DLL project
  8. In Visual Studio 2010, to create a DLL without template class, we have following steps:

    1. Create a Class library. the default it will create a dynamic library. please verify by Project Properties->Configuration Properties->General->Project Defaults->Configuration Type: dynamic library. make sure NO common language runtime support.
    2. Add header Printable.h. make sure following __declspec(dllexport) and __declspec(dllimport) are used:
      #ifdef COMPILE_MYLIBRARY
      #define MYLIBRARY_EXPORT __declspec(dllexport)
      #else
      #define MYLIBRARY_EXPORT __declspec(dllimport)
      #endif
      class MYLIBRARY_EXPORT PrintableInt {};
    3. Project Properties-> Configuration : ALL Configuration
    4. Project Properties->Configuration Properties->C/C++-> Preprocessor-> preprocessor definition: COMPILE_MYLIBRARY;
    5. Add source file Printable.cpp(in my project it is MyLibX.cpp. either way is fine).
    6. Add MyLibXClient console application.
    7. specify Include Path. Make sure All Configuration is selected from "configuration" dropdown:
      from project properties->configuration Properties -> C/C++ -> General->Additional Include Directies: type, ..\MyLibX
      Make sure All Configuration Type is selected.
      it will tell VS 2010 where to find PrintableInt.h file. if you compile the client app now, you will have link error.
    8. specify Lib file. it is to specify the path to the .lib file of the library project. note your DLL projects will create a .LIB file so that this console app will link against the DLL automatically.
      Linker->Input-> Additional Dependencies
      type such as ..\MyLibX\$(IntDir)\MyLibX.lib
    9. from Visual Studio 2010, referencing a DLL is simplified.
      project properties->common properties->Framework and Reference->Add New Reference button: you can add MyLibX project in.
      when you compile it, it will fail because it needs MyLibX.lib. to create this MyLibX.lib file, __declspec(dllexport) must be used.

      in Visual Studio 2010, we still need to set up include directories in the above step: Configuration :
      configuration properties->Linker->General->Additional Library Directories: type relative path.
      My Note: I tested that this step is not needed after adding reference.

      I also tested this step: with adding reference to MyLibX , we don't need to set up this step:
      configuration properties->Linker->Input->Additional Dependencies:type lib name such as MyLibX.lib. or we can type relative path plus lib name such as ..\MyLibX\MyLibX.lib

    it looks like template class can not create .lib file after validation. I tested on Visual Studio 2008. template class project will not produce .lib file.


  9. Basic C++ Win32 DLL
  10. Walkthrough: Creating and Using a Dynamic Link Library (C++)-- Visual Studio 2015
  11. Execute a function in any Win32 DLL - Reflection in Win32 DLL?
  12. DLL Tutorial For Beginners
  13. C++ Tutorial Create a DLL in VC++ 2013 or 2015
  14. C++ Tutorial: Create a DLL in VC++ 2010/2008
  15. Exporting C Functions for Use in C or C++ Language Executables
  16. Exporting from a DLL Using __declspec(dllexport)
  17. Importing into an Application Using __declspec(dllimport)

Layout manager

Saturday, January 20, 2018

VC++ property page setup/graphics

VS linker setups

__desclspec(dllexport) etc.

  1. A super easy DLL made in VC++ IDE, especially for the first time tasters
  2. HowTo: Export C++ classes from a DLL
  3. Basic C++ Win32 DLL
  4. Dlls are Simple. Part 1
  5. DLLs are simple: Part 2
  6. The Ultimate (DLL) Header File
  7. Win32/Linux Dynamic Library Loader Class
  8. A way for a MFC DLL to deal, at runtime, with BSTR from Visual Basic and from Visual C++

  9. Exporting C++ classes without using MFC extension DLL
  10. Exporting C++ Classes from an MFC Extension DLL
  11. Beginner's Guide
  12. Interface-based Programming, Runtime Class Discovery, Dynamic Class Loading from DLL
  13. A Beginner's Guide to Pointers
  14. Technical Guide on C
  15. Step by Step: Calling C++ DLLs from VC++ and VB - Part 1
  16. Step by Step: Calling C++ DLLs from VC++ and VB - Part 2
  17. Step by Step: Calling C++ DLLs from VC++ and VB - Part 3
  18. Step by Step: Calling C++ DLLs from VC++ and VB - Part 4
  19. Creating and consuming MFC DLLs for Beginners
  20. How to create a DLL library in C and then use it with C#
  21. Creating Import Library from a DLL with Header File
  22. Importing a Locally Defined Symbol without Using a Module Definition File
  23. DllExports - Common Problems and Solutions
  24. Calling methods from Dll compiled in 'C' from C#
  25. DLL Template which lets your project take off
  26. Understanding DLLs – Building them and Allowing External Calls to their Functions
  27. a Tiny Parser Generator v1.2

Saturday, January 13, 2018

Friday, January 5, 2018

C prototype tips

bit operations

string obfuscation

multi-threading

data grid

maker