Using WinRT with C?

Watching the // BUILD stuff, I saw that the WinRT API can be used with the C code:

enter image description here

I really like the fresh C API available for Win32 developers.

Where can I find information about the C WinRT API? How is this better than the existing Win32 C API?

+45
c visual-studio winapi windows-runtime
Sep 15 '11 at 19:10
source share
1 answer

WinRT is basically COM, so using WinRT components from C is similar to using COM components from C. As before, you get .idl files for all WinRT components, as well as .h files created from these .idl files. .H files include both C ++ and C declarations (wrapped in #ifdef __cplusplus as needed). You can simply # turn them on and start hacking.

This is not entirely accurate, although, for example, something like this C ++ / CX:

 Windows::UI::Xaml::Controls::TextBlock^ tb = ...; tb->Text = "Foo"; 

which is equivalent to this C ++ vanilla:

 Windows::UI::Xaml::Controls::ITextBlock* tb = ...; HSTRING hs; HRESULT hr = WindowsStringCreate(L"Foo", 3, &hs); // check hr for errors hr = tb->set_Text(hs); // check hr for errors tb->Release(); 

will be written in C as:

 __x_Windows_CUI_CXaml_CControls_CITextBlock* tb = ...; HRESULT hr; HSTRING hs; hr = WindowsCreateString(L"Foo", 3, &hs); // check hr for errors hr = __x_Windows_CUI_CXaml_CControls_CITextBlock_put_Text(tb, hs); // check hr for errors IUnknown_Release(tb); 

Take a look at "C: \ Program Files (x86) \ Windows Kits \ 8.0 \ Include \ winrt" in the Preview Preview to view the .idl and .h files.

+65
Sep 15 '11 at 20:22
source share



All Articles