O'Reilly logo

Mastering Windows 8 C++ App Development by Pavel Yosifovich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Application Binary Interface

The Calculator WinRT class created in the previous section leaves some questions. Suppose the following method was added to the public section of the class:

std::wstring GetResultAsString();

The compiler would refuse to compile this method. The reason has to do with the use of std::wstring. It's a C++ type—how would that project into C# or JavaScript? It can't. Public members must use WinRT types only. There is a boundary between the internal C++ implementation and the public-facing types. The correct way to define the method in question is this:

Platform::String^ GetResultAsString();

Platform::String is the C++/CX wrapper over a HSTRING WinRT, which is projected as System.String to C# and to a JavaScript string

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required