Category Archives: Programming languages

Developing Universal Windows App (UWP) with Xamarin.Forms 2.0 in Visual Studio 2015

Visual Studio 2015 has “Blank App (Xamarin.Forms Portable)” project template that creates three separate C# projects for Android, iOS and Windows.Phone 8.0 platforms that share the same C#/XAML code via so called PCL (Portable Class Library):

Blank App (Xamarin.Forms Portable)

(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…)

Combining OpenGL and XAML together in a Universal Windows App (UWP)

Visual Studio 2015 allows easily combine OpenGL graphics with XAML controls in a single window. To accomplish this task we can create a new project based on “XAML App for OpenGL ES (Universal Windows)” template:

XAML App for OpenGL ES (Universal Windows)

(more…)

How to multiply a value by a constant in WinRT XAML

The easiest way to accomplish this task is to use converter provided below. It is written in C++ but this convertor can be easily converted to C#:

[Windows::Foundation::Metadata::WebHostHidden]
public ref class MultiplicationConverter sealed : Windows::UI::Xaml::Data::IValueConverter
{
public:

    virtual Platform::Object^ Convert(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);

    virtual Platform::Object^ ConvertBack(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);

private:

    Platform::Object^ InternalConvert(Platform::Object^ value, Platform::Object^ parameter, bool forward);
};

(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…)

How to install Java Plug-in for FireFox browser on Windows

Probably it is a trivial question, but the answer is not always obvious. The main rule is to follow the right link like this: https://www.java.com/en/download/help/firefox_online_install.xml. As the result you will get:

JavaPlugin for FireFox

To check if it works or not follow this link: http://java.com/en/download/installed8.jsp.

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 debug a PHP script

It could be useful sometimes to know what variables are defined at particular point of PHP script in order to have a better understanding of the code you are debugging. In contrast with C++, PHP has a magic function get_defined_vars ( void ) that  returns an array of all defined variables with their values so we can output all variable names with the following line of code:

print_r(array_keys(get_defined_vars()));

(more…)