Monthly Archives: February 2018

Building Log4cpp with VS2017

First, download log4cpp on sourceforge at .Latest version is 1.1.3. Let’s decompress the archive.
Go to logcpp/msvc10 folder. Open the mvc10.sln and upgrade the project to latest SDK and Visual Studio 2017 (v141). Done.
Build the log4cpp project… There is an error about a custom build step on file

We need to go into the folder msvc10 of the src and compile the event viewer definition file (.mc). You need to open Developer Command VS2017:

cd D:\Dev\log4cpp-1.1.3\log4cpp\msvc10>

MC: Compiling

D:\Dev\log4cpp-1.1.3\log4cpp\msvc10>rc -r -fo NTEventLogCategories.res NTEventLogCategories.rc Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384 Copyright (C) Microsoft Corporation. All rights reserved.

D:\Dev\log4cpp-1.1.3\log4cpp\msvc10>link /MACHINE:IX86 -dll -noentry -out:NTEventLogAppender.dll NTEventLogCategories.res Microsoft (R) Incremental Linker Version 14.12.25830.2
Copyright (C) Microsoft Corporation. All rights reserved.

Then in Visual Studio, remove the file from the project and let’s BUILD !
There is a compiler error. To solve it: add HAVE_SNPRINTF to the Preprocessor definitions… and REBUILD ! Now it is successful:

1> Creating library Debug\log4cpp.lib and object Debug\log4cpp.exp
1>log4cpp.vcxproj -> D:\Dev\log4cpp-1.1.3\log4cpp\msvc10\log4cpp\Debug\log4cpp.dll 1>Done building project “log4cpp.vcxproj”.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Unicode, TCHAR, STL std::string & std::stringw and building in mode x64

When you build a Visual Studio project, you have to consider multiple project options:

The Character Set option is very important in the way you will write code. Microsoft wants every developer to build with “Use Unicode Character Set” but bad habits were taken by developers.
They have preferred the option “Use Multi-Byte Character Set (MBCS)” where strings are things you put in “” and that’s all !

So what is the problem Doctor ? Handling Unicode allows you to target multiples languages and it’s the way we build modern softwares.
To help you achieve your migration or your new software, Microsoft provides TCHAR.h with a lot of macros:

– TCHAR means char in MBCS and wchar_t in Unicode

– _T(“toto”) means “toto” in MBCS and L”toto” in Unicode
To properly call routines of the CRT using TCHAR, you have to notice the name of the functions that care of TCHAR : Example: printf -> Unicode: wprintf, TCHAR: _tprintf
If you use _tprintf and #include , the function _tprintf will be expanded using the right function name.

TCHAR szLisa[10] = _T(“Lisa”);
_tprintf(_T(“%s\n”), szLisa);

But the question is : How do I switch from one mode to another. Example, I use STL, I can have std::string or std::wstring. Using STL strings has a mode that let you recover the characters using the c_str() function.

std::wstring s1 = szLisa;
std::wcout << s1 << std::endl;

If you want to dump from one world to another, the STL has a way:

std::string s2(s1.begin(), s1.end());
std::cout << s2 << std::endl;

C++ OOP Fundamentals

Next month in Programmez Magazine, you will find an article avec OOP with C++. It covers the basic of OOP, how to dive into , how to think and create code. Make your own classes and design behaviours in your classes !


MCP Programming C# PASS

I have passed the 70-483 “Programming C#” exam from Microsoft. It is a large scope game of questions… I must admit it was not so easy. But the most important is to pass it and now change my mind with others things !


Next month, it’s C++ & OOP Fundamentals

In the march Edition of french magazine Programmez, you will find a technical article about OOP in C++.

How to create an object model, thinking about how to create smart classes, how to hide or not members, abstract classes, virtual functions….

Envoyé de mon téléphone Windows 10