Category Archives: C++

How to compile QT with VS2015 and GCC

Below I provided a simple step by step instruction on how to compile QT 5.7 with VS2015 assuming you already have VS2015 and Git client installed on your Windows machine.

Install Perl, Python and Ruby.

To get QT 5.7 sources open Git Bash and run the following command (the repository has some submodules, so “recursive” option is required), see the list of possible clone here at the bottom of the page:

git clone --recursive https://github.com/qtproject/qt5.git --branch 5.7

Create a bat file called configureqt.bat with the following content:

set PATH=%PATH%;"C:\Program Files (x86)\Portable\ruby-2.3.0-i386-mingw32\bin";C:\Perl\bin;C:\Python27
D:
cd D:\Repos\qt5\
set _ROOT=D:\Repos\qt5
set PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
set QMAKESPEC=win32-msvc2015
set _ROOT=
configure -debug -nomake examples -opensource

(more…)

Using OpenGL 3.0 with MSOpenTech ANGLE

Typically ANGLE library is used with OpenGL 2.0, but I successfully tried to enable OpenGL 3.0:

const EGLint contextAttributes[] = 
{ 
    EGL_CONTEXT_CLIENT_VERSION, 3, 
    EGL_NONE
};

and used some OpenGL 3.0 features in my Universal Windows App. But today I tried to compile my application with the new version of ANGLE library and got EGL_BAD_CONFIG error while creating the OpenGL context. The source code that returns this error checks some EGL_OPENGL_ES3_BIT_KHR that is not set in the new version:

if (clientMajorVersion == 3 && !(configuration->conformant & EGL_OPENGL_ES3_BIT_KHR))
{
    return Error(EGL_BAD_CONFIG);
}

(more…)

Debugging a C++ application on an Android device with VS2015 on Windows 10

VS2015 has an exciting ability to debug a C++ application on Android Emulator, but in this article I will talk about no less exciting and more time expensive ability to debug a C++ application on a real Android device. The first thing we need to spend the time with is figuring out how to enable USB debugging mode on our Android device. On my ASUS Zenfone I need to go to Settings->About->Software Information and tap on Build Number 7 times, after that I have USB debugging check box in Settings->Developer Options that I should tap as well:

enabling USB debugging mode on Android device USB debugging mode on Android device

(more…)

Listening to a dependency property changes in Universal Windows App in C++

If you want to be notified when some dependency property of a control changes, for example, UIElement::Visibility, you can do the following trick. First declare you own dependency property of the same type in some class:

public ref class MyListener
{
public:

    static property Windows::UI::Xaml::DependencyProperty ^ BoundVisibilityProperty
    {
        Windows::UI::Xaml::DependencyProperty ^ get() { return boundVisibilityProperty; }
    }

    property Windows::UI::Xaml::Visibility BoundVisibility
    {
        Windows::UI::Xaml::Visibility get() { return safe_cast<Windows::UI::Xaml::Visibility>(GetValue(boundVisibilityProperty)); }
        void set(Windows::UI::Xaml::Visibility value) { SetValue(boundVisibilityProperty, value); }
    }

    static Windows::UI::Xaml::DependencyProperty ^ boundVisibilityProperty;

    static void OnBoundVisibilityChanged(DependencyObject^ d, Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ e);
};

(more…)

Initialization of UWP C++ XAML application

UWP C++ applications based on “DirectX 11 and XAML App” or “XAML App for OpenGL ES“ project templates have some partial App class defined in user code and in generated file App.g.h:

partial ref class App :  public ::Windows::UI::Xaml::Application,
    public ::Windows::UI::Xaml::Markup::IXamlMetadataProvider
{
public:
    void InitializeComponent();
    [Windows::Foundation::Metadata::DefaultOverload]
    virtual ::Windows::UI::Xaml::Markup::IXamlType^ GetXamlType(::Windows::UI::Xaml::Interop::TypeName type);
    virtual ::Windows::UI::Xaml::Markup::IXamlType^ GetXamlType(::Platform::String^ fullName);
    virtual ::Platform::Array<::Windows::UI::Xaml::Markup::XmlnsDefinition>^ GetXmlnsDefinitions();
private:
    ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ _provider;
    bool _contentLoaded;
};

the user code:

ref class App sealed
{
public:
    App();
    virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) override;
    ...
};

(more…)

Creating cross platform (Android, iOS, UWP) OpenGLES 2 applications with VS2015

Cross platform (Android, iOS, UWP) OpenGLES 2 application can be easily created in VS2015 using “OpenGLES 2 Application (Android, iOS, Windows Universal)” project template:

“OpenGLES 2 Application (Android, iOS, Windows Universal)” project template

(more…)

Using Visual Leak Detector with MS Visual Studio 2013

Go to Tools->Extensions and Updates, download and install Using Visual Leak Detector:

Using Visual Leak Detector

Create a header file, named, for example, CommonTools.h containing the following:

#pragma once

#include "C:\Program Files (x86)\Visual Leak Detector\include\vld.h" 

#pragma comment(lib, "C:\\Program Files (x86)\\Visual Leak Detector\\lib\\Win32\\vld.lib")

Include CommonTools.h in at least one file in all the C++ projects in your solution. Build debug version of the program. Visual Leak Detector will write the information on memory leaks to Output window when the program exits.

How I fixed “error LNK2005: _DllMain@12 already defined in msvcrtd.lib”

Today I got “error LNK2005: _DllMain@12 already defined in msvcrtd.lib” while linking some C++ CLI project with MFC support in MS Visual Studio 2013. As described in A LNK2005 error occurs when the CRT library and MFC libraries are linked in the wrong order in Visual C++A LNK2005 error occurs when the CRT library and MFC libraries are linked in the wrong order in Visual C++ article, I added /verbose:lib linker option:

MS Visual Studio Linker options

(more…)

Using a WPF control in a MFC application

I’ve been working on some MFC application and to apply my WPF knowledge I added a WPF control written in C# to my MFC CView with the following code:

int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;

    try
    {
        gcroot<hwndsource ^> hwnd_source = gcnew HwndSource(0, WS_VISIBLE | WS_CHILD, 0, 0, 0, "HwndSource", IntPtr(m_hWnd));

        MyWpfControl ^ control = gcnew MyWpfControl();

        hwnd_source->RootVisual = control;
    }
    catch (Exception ^ ex)
    {
        String ^ msg = ex->Message;
    }

    return 0;
}

All that I needed to do is to follow the steps described in this post: How do I host WPF content in MFC Applications, fix VS2012 bug described here, and got rid of std::mutex and std::lock_guard replacing them with the following classes using typedefs:

(more…)

How to compile BOOST with MS Visual Studio 2010-2017

Fortunately, to compile BOOST with MS VC 2010 we need Visual Studio Command Prompt and five commands:

Navigate to BOOST directory, for example:

F:
cd F:\Projects\Lib\boost_1_53_0

(more…)