1 / 40

Windows ストアアプリを C++/CX で作る

Windows ストアアプリを C++/CX で作る. Hokuriku.NET vol.12 2013/8/3 Sat 遥佐保(はるか・さお). はじめに. 自己紹介. @ hr_sao コミュニティ Room metro (大阪) ExceptionalC ++ 読書会(大阪 ) SQLWorld (大阪) Microsoft MVP for Client App Dev [ Jan,2010 - Dec,2013] . 本日 の 目的. C++/CX に対する 理解度 を深める. 注意点. 網羅性があるわけでは ありません

starr
Télécharger la présentation

Windows ストアアプリを C++/CX で作る

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WindowsストアアプリをC++/CXで作る Hokuriku.NET vol.12 2013/8/3 Sat 遥佐保(はるか・さお)

  2. はじめに

  3. 自己紹介 @hr_sao コミュニティ Room metro(大阪) ExceptionalC++読書会(大阪) SQLWorld(大阪) Microsoft MVP for Client App Dev [Jan,2010 - Dec,2013]

  4. 本日の目的 C++/CXに対する 理解度を深める

  5. 注意点 網羅性があるわけではありません 個人の体験と志向に基づきます

  6. Topics How about C++/CX Windows Store Apps grammar How to program Problem summary

  7. 1. How about C++/CX

  8. Now… use cases for C++ メリット 1. Portability LinuxとWindowsで同じコードを動かす 2. Reusability    既存ライブラリ使いたい 3. Performance .NETがリッチすぎる こういうところに憧れる…?

  9. Why Language Extensions? 例えば、WindowsでC++を使う人の本音は ファイルの操作、もっと楽に出来ないのかなぁ 表示といえば、MFC/DirectX/GDI…なんでこんなにコーディング量多いの…( ̄д ̄) エー いつも「それC#がよしなにやってくれるよ」と言われる Java/C#使いたくない!! そこでC++の拡張です!

  10. C++/CX CLIはマネージ CXはネイティブ C++言語の拡張 (/ZWオプション) Visual C++ コンパイラの拡張機能です C++11対応 C++/CLI のサブセットに相当します Windows ストアアプリの作成用 ※ストアアプリ以外でも利用可能

  11. 2. Windows Store Apps

  12. Windows Store Appshttp://msdn.microsoft.com/ja-jp/library/windows/apps/hh974576.aspx Windows 8 デバイス上で動作する新しい種類のアプリケーション ウィンドウは1つ タッチUIが快適 アプリ同士の連携 アプリバー・チャームバー タイル

  13. デスクトップからも呼べるよ※XAML/HTML系以外 WinRTはAPI– 言語 Desktop apps 単なるインタフェース 実体はDLL Windows store apps HTML JavaScript C# VB C C++ HTML / CSS XAML DirectX JavaScript C#/VB C/C++ WinRT APIs Devices & Printing Communication & Data Graphics & Media .NET SL Internet Explorer Win32 Application Model Windows Kernel Services

  14. Windows Runtimeを各言語から利用 C++/CX ⇔ C#/VB JavaScript ⇒ C++/CX , C#/VB

  15. Windows Runtime APIs アプリケーションバイナリインタフェース(ABI) バイナリレベルの互換が保障 ABIを利用してAPIを提供 Application binary Interface (ABI) Windows Runtime APIs Devices & Printing Communication & Data Graphics & Media Application Model Windows Kernel Services

  16. WinMDで紐付け メタデータを記載している Windows Runtimeの実体はEXEやDLL HKLM\Software\Microsoft\WindowsRuntime\ActivatableClassId

  17. Visual Studio 2012のC++の世界 Store apps Desktop DirectX apps for phone MFC WRL WTL DirectX XAML for C++ Windows8 WindowsPhone8

  18. (余談)Windows Runtime C++ Template Library (WRL)http://msdn.microsoft.com/ja-jp/library/vstudio/hh438466.aspx WindowsRuntimeのコンポーネントを作成できるテンプレートライブラリ ABIレベルで動作 直接COMアクセスできる C++/CX使わなくてもいい デモ: ABI::Windows::UI::Notifications

  19. WindowsStoreApps環境(UI XAML)http://msdn.microsoft.com/ja-jp/library/windows/apps/jj160326.aspx OS process 混ぜるな危険! C++実装クラス (ネイティブ) App container ( package manifest ) UI controls ( XAML ) 相互互換のための C++言語拡張機能 (中間の変換無し) VSプロジェクト テンプレート C++/CX Windows Runtime Win32 and COM STL PPL CRT Windows Kernel Services

  20. Access Documents-Pakage.appxmanifest

  21. 3. grammar

  22. C++/CXの文法抜粋http://msdn.microsoft.com/ja-jp/library/windows/apps/br212455.aspxC++/CXの文法抜粋http://msdn.microsoft.com/ja-jp/library/windows/apps/br212455.aspx enumclass {} Platform::Object^ Platform::String^ T^ 識別子 T% 識別子 ref new

  23. ポインター:^http://msdn.microsoft.com/ja-jp/library/yk97tc08.aspxポインター:^http://msdn.microsoft.com/ja-jp/library/yk97tc08.aspx Windows Runtimeオブジェクトへのポインタ C++標準の std::shared_ptr* と同等 参照カウンタを取る コピー可能(所有元をカウント) ムーブ可能(データコピーは発生しない) GC対象 C++の場合、配列/文字列などムーブかコピーか選択出来る

  24. ref new / sealedhttp://msdn.microsoft.com/ja-jp/library/0w2w91tf.aspxhttp://msdn.microsoft.com/ja-jp/library/windows/apps/hh699870.aspx WindowsRuntimeオブジェクトを割り当て C++標準の new 相当=ref new C++標準の final 相当=sealed ref class Person sealed{ ← Person^ p =ref new Person(); public: Person(); property Windows::Foundation::Metadata:: … }

  25. 文字列:String Windows Runtimeで利用する文字コードはUTF-16 内部処理は std::wstring or L“xxx” XAML/外部公開は Platform::String^ // 直接代入 Platform::String^ str1 = “aaa”; // String⇒wstring std::wstring ws1( str1->Data() ); // wstring⇒String Platform::String^ str2 = ref new String( ws1.c_str());

  26. XAMLObjを利用可能なpointerに <Button x:Name="btn00" Content="Cleck me :)"/> MainPage.xaml AutoGenerated void ::StoreApp1::MainPage::InitializeComponent() { … btn00= safe_cast<::Windows::UI::Xaml::Controls::Button^> (static_cast<Windows::UI::Xaml::IFrameworkElement^> (this)->FindName(L"btn00")); … } MainPage.g.hpp

  27. 4. How to program

  28. ストアアプリでC++を選択したら… MSDN : C++ を使った Windows ストア アプリのためのロードマップ http://msdn.microsoft.com/ja-jp/library/windows/apps/xaml/hh700360.aspx WindowsストアアプリのためのC++情報まとめ concurrency::create_async … task– then(), when_all() … casablanca – C++ REST SDKbindings to HTTP, JSON, and URIs

  29. Hilo Windows7の時はDirectXでした 今はC++/XAML版と、JavaScript版があるよ http://hilo.codeplex.com/ C++とXAMLを利用するための実践的サンプル

  30. Hilo C++/CXプログラミングノウハウ 型変換のオーバーヘッドに気を付ける Refクラスは相互運用を目的とする 内部型を public ref クラスで公開しない …などなど

  31. Casablanca – C++ REST SDK HiloでWindowsストアアプリの作り方を覚えたら、次は通信がしたくなるhttp://casablanca.codeplex.com/

  32. Casablancaとは RESTサービス(Windows Vista/7/8, Linux) VS2010/2012, クラウドベースの通信サポート 非同期処理、ストリームバッファ HTTP Client C++11 base Apache オープンソース Azureなど

  33. 5. problem

  34. 実際には 「Windowsストアアプリ用」の設計を 理解する必要があります

  35. 実際やってみると障害 型違いによるコンパイルエラー ネイティブC++型をpublic メンバとするアプリケーション設計 だいたいC++のふりしてさ…(*´Д`) そもそもサンプルソースコードや解説が少ない様に感じる 学習してもつまづく部分が多い C++という言語を知っているがゆえに、ストア用設計に頭が切り替わりにくい

  36. 例)Webから情報をとってきたい #include <pplx.h> #include <http_client.h> などインクルードしないといけない public ref class MainPagesealed{ public: MainPage(); private: pplx::task<void> get_http_request(); }; using namespace concurrency; using namespace pplx; using namespace web::http::client; など宣言しないといけない

  37. 例)ヘッダファイルに追加したい MainPage.xaml.hにincludeファイルを追加する  →App.xaml.cppでエラーが出る(場合もある) 全てのincludeファイルを pch.h (プリコンパイルヘッダ)に固定化ヘッダファイルとして追加する →コンパイル時メモリ不足になる(場合もある)

  38. 例)何がダメだったのか? MainPage.xamlに 通信処理をまるっと入れようとしたのが 間違い ネイティブで処理できる処理と、 Windowsストアアプリの処理の境界は?

  39. summary

  40. まとめ C++/CXはVisual C++コンパイラの拡張機能 コンパイルオプションは /ZW Windows Runtime APIはABI互換 C++ネイティブとC++/CXの役割は異なる public 部分→Platform名前空間 情報は多いが、実際には慣れが必要

More Related