Print visual studio definitions at build-time.

Use the following code to check the values of common visual studio defines.

These defines are used inside Microsoft and other libraries. This macro can be used to print the values to the compiler output. For example, before and after certain header files are included.

#define _DEFINE_TO_STRING_(x) #x
#define _DEFINE_TO_STRING(x) _DEFINE_TO_STRING_(x)

#pragma message("_MSC_VER      is " _DEFINE_TO_STRING(_MSC_VER))
#pragma message("_MFC_VER      is " _DEFINE_TO_STRING(_MFC_VER))
#pragma message("_ATL_VER      is " _DEFINE_TO_STRING(_ATL_VER))
#pragma message("WINVER        is " _DEFINE_TO_STRING(WINVER))
#pragma message("_WIN32_WINNT  is " _DEFINE_TO_STRING(_WIN32_WINNT))
#pragma message("_WIN32_IE     is " _DEFINE_TO_STRING(_WIN32_IE))
#pragma message("NTDDI_VERSION is " _DEFINE_TO_STRING(NTDDI_VERSION)) 

// "Header file under investigation"
#include "stdafx.h"

#pragma message("_MSC_VER      is " _DEFINE_TO_STRING(_MSC_VER))
#pragma message("_MFC_VER      is " _DEFINE_TO_STRING(_MFC_VER))
#pragma message("_ATL_VER      is " _DEFINE_TO_STRING(_ATL_VER))
#pragma message("WINVER        is " _DEFINE_TO_STRING(WINVER))
#pragma message("_WIN32_WINNT  is " _DEFINE_TO_STRING(_WIN32_WINNT))
#pragma message("_WIN32_IE     is " _DEFINE_TO_STRING(_WIN32_IE))
#pragma message("NTDDI_VERSION is " _DEFINE_TO_STRING(NTDDI_VERSION)) 


Building Boost X for platform Y

How to build the Boost C++ library for different targets.

This is an example of building Boost 1.55 for Visual Studio 2017 (toolset v141)

  1. Run bootstrap.bat
  2. Edit project-config.jam
  3. Call b2.exe with the correct parameters
  1. Run bootstrap.bat

This should create the b2.exe executable that is the build manager for the Boost library.

2. Edit project-config.jam

Visual studio 2017 is MSVC 15 (https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd)

import option ; 
 
using msvc : 14 : "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\cl.exe";
 
option.set keep-going : false ; 

3. Call b2.exe with the correct parameters

Documentation for the B2 tool can be found here: https://boostorg.github.io/build/manual/master/index.html

The toolset is 14.1 (v141). And we want the libraries for x64.

> b2 toolset=msvc-14.1 address-model=64

We want static libraries (not dll):

> b2 toolset=msvc-14.1 address-model=64 link=static

We can specify to build Release or Debug versions:

> b2 toolset=msvc-14.1 address-model=64 link=static variant=release

With different build, it can be usefull to direct all output (created libraries) to a specific folder:

> b2 toolset=msvc-14.1 address-model=64 link=static variant=release --build-dir=.Output-x64-static-release


C++ (legacy) quality tools

Have you ever questioned why not all software teams are able to work at the same speed?

This article by Dirk-Jan Swagerman, outlines the hidden costs of “owning” software, and what business leaders can do to take control of their legacy software.

The hidden costs of software inventory

How to know, control, and improve the quality of your applications written with legacy C++ applications. Where to invest time to increase maintainability? How to reduce complexity to allow new developers to quickly get up to speed when joining the team?
Let’s think about C++ application written in C++ with use of MFC, COM interfaces and libraries that are only compatible with Visual Studio 2010 😉 I want to have an integration of various significant tools running in Jenkins.
What tools can I used to achieve this?

Unit testing

When I develop or refactor code, I do not want to unintensionaly effect other parts of the system. I want to verify this quickly. Then I use unit tests.

  • Catch2 (not compatible with Visual Studio 2010 compiler)
  • Boost.Test

Static Code Analysis

I want a tool to warn me for possible errors in the code.

  • CppCheck

Memory leak testing

I want a tool to identity memory (de)alocation errors.

  • Visual Studio CRT (under investigation)
  • Dr.Memory (under investigation)

Application testing

I want to test my application by simulation a user. I want to replay use cases and test the reponse of the application. I do not want repetative manual tests. I want a tool that can recognize the id’s, names and classes of Win32 controls (like shown by Spy++).

  • PyWinAuto (Python)

Code metrics

I want to quantify, control and observe the size and quality of my code. I want to measure and to improve maintainability and to decrease complexity.

  • Not available in Visual Studio 2010.
  • CCCC (produces HTML output)
  • SourceMonitor (no Jenkins plugin for latest version)

Continuous integration

I want everything to be done and checked automatically, preferably when I am sleeping at night…

  • Jenkins


Redirecting error messages from Command Prompt

To print the errors and standard output of an executable to a single file by using the &1 command to redirect the output for both STDERR to STDOUT and then sending the output from STDOUT to a text file:

app.exe 1> output.txt 2>&1


Clone Git repository with credentials in Jenkins Pipeline from HTTP url.

Here is explained how to use your (Git) credentials to clone or checkout from a repository that is only accessible by http (i.e. not by ssh or https) in a Jenkins Pipeline script. Using a username, password and http is a simple way of doing this. Think about configuring your system to use https or ssh.

Jenkins Requirements

Install the “Credentials Plugin”

GitHub requirements:

Know your username, the password and the http url to access the repository.

Add your credentials to the Credentials plugins of Jenkins

Jenkins menu -> Credentials -> Select the store -> Select Global credentials

In menu at left, select add Credentials

In the form, enter the following information

Kind : choose “username and password”

Scope: global

Username: git user name

Password: git password

!NOTE! Is your password contains special characters like @, #, // or anything that can corrupt a command line or url, than it is easier to change your password into only letters and numbers.

ID: leave blank as it will be generated by the Jenkins plugin (in this example we imagine the ID generated is xyz)

Description: My GitHub credentials

Press OK.

The generated ID will be used in the Jenkins pipeline, you can copy/past the ID.

Pipeline script

  1. Define the credentials in the environment
pipeline {
   agent any
   environment 
   { 
       // replace xyz with the copy pasted iD
       GitHubUser = credentials('xyz')  
   }
   ...

This will generate variable that can be used in your script. The names start with the name of the variable ‘GitHubUser’ and postfix _USR and _PSW are added. So the two resulting variables we are going to use are:

GitHubUser_USR
GitHubUser_PSW

2. Create a pipeline stage to checkout the repository. In this example, we clone into an empty directory, but you can use the git checkout command as well.

stage('Checkout'){
   steps   {        bat "git clone http://$GitHubUser_USR:$GitHubUser_PSW@example.com/project.git"   }
}

3. Run the script

The actual username and password are NOT DISPLAYED in the logging.

They will appear like ****:

C:\Jenkins\\Dev>git clone http://****@example.com/project.git
Cloning into 'project'...


Git commands explained

A translation of common Git commands in normal, understandble(?) words.

git add : Stage a file. Add it from your workspace into the staging area (or index). Workspace edits is not changed. After this add command, your files are ready to be committed (by a commit command later)

git rm — cached : Unstage a file. Remove the file from the staging area. Workspace edits is not changed. After this rm command, your file is not longer ready to be commited.

git commit : Bundle all the files that are in the staging area and copy them to the local repository. After a commit command, the staging area is empty again, and your bundle of files is nicely stored in the repository with a date, author and description. They have become part of the history.

git checkout : Updates files in the workspace to match the contents of another branch or commit. After this checkout you are ready to continue programming but you are (re-)starting from another point in the tree or in thetimeline.

git revert : Create a a bundle of files that contains the necessary changes to undo a commit. After this revert command you have created a NEW(!) commit that reverses an earlier commit.

git reset –soft : Undo a change (commit) in the local repository. After this reset we are ready to (re-)commit again.

git reset (–mixed) : Undo a change (add) in the staging area. After this reset we are ready to (re-)add again.

git reset –hard : Undo a change (local edit, aka programming) in the workspace.After this reset we lost our changes and are ready to (re-)edit again. This only effects tracked files.

git clean -f -d : Removes all the untracked files and folders with untracked files from the workspace. After this clean you can start adding ew files. Use -n instead of -f to inspect the files/folders before actuallty deleting them.


Pass data from ASP.NET MVC view to controller with Ajax and JSON

This is an example of passing data consisting of multiple arguments from your webpage (i.e. a MVC view) to the server (i.e. a MVC Controller).
We will post the data from JavaScript with Ajax, so it means we will not request a new page from the server, just passing data to the controller. We will send the data in JSON format so it can be parsed (easy and strongly typed) in the controller.

Continue reading


Handling a ASP.NET MVC ActionLink click within a DNN Module

The problem: DNN is taking care of routing,  that means it is not possible to use System.Web.Mvc.HtmlHelper to create the right URL that you want. DNN will not understand the URL’s created by the standard Microsoft Html or Url helper. The DNN module is embedded in a DNN page and the we need some additional information to access the controller that it part of the module in the page. A page can also include multiple modules. We need to retrieve that information from DNN and DNN includes its own versions of the Html and Url helpers provide that information. This example shows how you can use it,

How to use DotNetNuke.Web.Mvc.Helpers.HTMLhelper and DotNetNuke.Web.Mvc.Helpers.DnnUrlHelper to call the Action functions in your MVC controller
Continue reading


Module development with DNN 9 and Visual Studio Community 2017

How to create a module for DNN 9 (DotNetNuke) based on your own C# ASP.NET Web page

I explain to how setup and development environment using Visual Studio Community 2017. The modules will be creating with help of the DNN9 templates. The setup is prepared for development with ASP.NET Core and Razor.

Continue reading


Enable build selection (debug or release) in Visual Studio 2010 Express

In the menu tools select settings. Here’s an expert mode you can enable.
Again in the tools menu select options. Open the item calles projects and solutions. On the general page you can enable show Advanced build configurations.