Msdn reference for winrt: http://msdn.microsoft.com/en-us/library/windows/apps/hh454062 (V = vs.110). aspx
First, declare that the Hello, world program is not the winrt of Metro style, and the winrt program in Metro can find a lot of relevant information (of course, many articles on the Internet are not suitable for beginners, ). I personally prefer to start with simple, so it is not better to know winrt from the desktop program?
(1) Is it winrt?
For more information about winrt, go to the Internet to search for it. Many people are discussing it. (Of course, most of this stuff is currently in the discussion stage. After all, it is still preview ).
Generally speaking, winrt is a new API set provided by Win8. Unlike the traditional Win32, winrt provides APIs in OO mode, and winrt supports desktop programs, it also supports the metro Program (of course, the two are not the same ). In addition, the winmd file can be obtained after winrt compilation. winmd is a very important thing in Win8, similar to com and ,. net. winmd can be called across different languages (C #, C ++, VB, and JS) (of course, it is a Metro program ), for my personal understanding, winmd is similar to an interface definition or an interface export file. I will be able to understand it after further research.
(2) winrt for desktop app
Simply put, for desktop programs, winrt can be understood as a syntax extension with some new classes and syntax extensions.
(3) winrt compilation and link
Http://msdn.microsoft.com/en-us/library/windows/apps/hh441567 (V = vs.110). aspx
Compilation options:
/ZW enable WinRT language extensions/AI<dir> add to assembly search path <dir> is the folder where the compiler searches the winmd files /FU<file> forced using assembly/module force the inclusion of the specified winmd file/D "WINAPI_FAMILY=2" set this define to compile against the ModernSDK subset of Win32
Link options:
/APPCONTAINER[:NO] marks the executable as runnable in the appcontainer (only)/WINMD[:{NO|ONLY}] emits a winmd; if “ONLY” is specified, does not emit the executable, but just the winmd/WINMDFILE:filename name of the winmd file to emit/WINMDDELAYSIGN[:NO]/WINMDKEYCONTAINER:name/WINMDKEYFILE:filename used to sign the winmd file
The options will not be described one by one. The key is to try it.
(4) Hello, world with winrt
As follows:
// File: hello_winRT.cpp#include <stdio.h>#include <windows.h>#include <iostream>#include <string>using namespace Platform;int main(){String^ str1="a test";std::wstring wstr(str1->Data());std::wstring wstr1(str1->Data(), str1->Length());std::wcout<< wstr << std::endl;std::wcout<< wstr1 << std::endl;//printf("%s\n",wstr.c_str());//printf("%s\n",wstr1.c_str());system("pause");return 0;}// Compile with:// set_vs_vars.bat// cl hello_winRT.cpp /ZW /AI%winmd% /EHsc /MD// Result:// hello_winRT.cpp(24) : warning C4447: 'main' signature found without threading model. Consider using 'int main(array<Platform::String^>^ args)'.
Note: You can compile the command here under the command line. To simplify writing, I first set the environment variables with a simple bat, as shown below:
@echo OFFrem ## file: set_vs_vars.batset winmd="C:\Program Files (x86)\Windows Kits\8.0\Windows Metadata"echo winmd:echo %winmd%rem ##set env of vsecho setting vs environment...call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat";echo done
This, you know.
Describe the content of CPP above:
Here we use the string and using namespace platform of winrt. It is required. It is the command space of winrt. String ^ is the type of winrt, and there is nothing else. For compilation options,/ZW and/AI are required. Specify the path for using winrt and searching winmd files (winrt is defined in winmd files)./MD is also required, I don't know why/MT compilation will go wrong. I have redefined it. I didn't study it. If you are interested, please check it out. /Ehscc is not required. If you do not use it, a warning is displayed. This option sets whether to use vs exceptions. In addition, after compiling with the above options, there is still a warning that the main signature is incorrect and suggestions are given. As a result, after I change it to the suggestion, there is no entry point, nima is playing with me! I have not studied the question of this "entry". refer to the following article. I have used main for this purpose, but I have compiled it with vs. I have never tried it:
Http://msdn.microsoft.com/en-us/library/br229585
Http://code.msdn.microsoft.com/DWriteHelloWorld-760793d2/sourcecode? Fileid = 44736 & pathid = 309807482
PS: For winmd files, I have time to study them again. Here is an article http://www.cnblogs.com/waninlezu/articles/win8metadata.html, which may be used to open winmdfiles. After the above Hello, world compilation, A winmd file and an EXE file will be generated. Study this later.