Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
975 views
in Technique[技术] by (71.8m points)

visual studio - Using WinRT from C?

Watching the //BUILD stuff, I saw that WinRT API's can be consumed by C code:

enter image description here

I am rather excited about a fresh C API available to Win32 developers.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

WinRT is fundamentally COM, so using WinRT components from C is like using COM components from C. Like before, you get .idl files for all WinRT components, and also .h files produced from those .idl files. The .h files include both C++ and C declarations (wrapped in #ifdef __cplusplus as needed). You can just #include them and start hacking away.

It's not exactly neat, though, e.g. something like this C++/CX:

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

which is equivalent to this vanilla C++:

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

would 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);

Look inside "C:Program Files (x86)Windows Kits8.0Includewinrt" in Developer Preview to see the .idl and .h files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...