从C使用WinRT的? [英] Using WinRT from C?
问题描述
看着//建立的东西,我看到的WinRT API的可以被C code消耗:
我比较兴奋,可到Win32开发一个新的C API。
在哪里可以找到关于C的WinRT API的信息?它是如何比现有的Win32 C API更好?
WinRT的根本COM,因此使用从C是像以前一样利用C.像COM组件,你得到的.idl文件所有的WinRT组件的WinRT组件,以及同样的.h从这些文件的.idl产生的文件。该.h文件包括C ++和C声明(根据需要放在的#ifdef __cplusplus
)。你可以只#包括它们并开始劈砍而去。
这不完全整齐,虽然,例如像这样C ++ / CX:
的Windows UI :: :: XAML中::控制:: TextBlock的^ TB = ...;
TB->文字=富;
:相当于这香草C ++ 的Windows UI :: :: XAML中::控制:: ITextBlock * TB = ...;
HSTRING HS;
HRESULT HR = WindowsStringCreate(L富,3,&安培; HS);
//检查小时的错误
HR = TB-> set_Text(HS);
//检查小时的错误
TB->发行();
将被写在C为:
__ x_Windows_CUI_CXaml_CControls_CITextBlock * TB = ...;
HRESULT小时;
HSTRING HS;
HR = WindowsCreateString(L富,3,&安培; HS);
//检查小时的错误
HR = __x_Windows_CUI_CXaml_CControls_CITextBlock_put_Text(TB,HS);
//检查小时的错误
IUnknown_Release(TB);
看看。C:\\ Program Files文件(x86)的\\的Windows套件\\ 8.0 \\ \\包含WinRT的,在开发preVIEW看到的.idl和.h文件
Watching the //BUILD stuff, I saw that WinRT API's can be consumed by C code:
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?
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 Kits\8.0\Include\winrt" in Developer Preview to see the .idl and .h files.
这篇关于从C使用WinRT的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!