1 / 34

Elemar Júnior (@ elemarjr ) Microsoft Visual C# MVP elemarjr

C# e C++/CX – O que há de novo nas linguagens para suportar o desenvolvimento de aplicações modernas. Elemar Júnior (@ elemarjr ) Microsoft Visual C# MVP http://elemarjr.net. aka.ms/ roslyn. #include < windows.h > #include < shobjidl.h >

tynice
Download Presentation

Elemar Júnior (@ elemarjr ) Microsoft Visual C# MVP elemarjr

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. C# e C++/CX – O que há de novo nas linguagens para suportar o desenvolvimento de aplicações modernas Elemar Júnior (@elemarjr) Microsoft Visual C# MVP http://elemarjr.net

  2. aka.ms/roslyn

  3. #include<windows.h> #include<shobjidl.h> intWINAPIwWinMain(HINSTANCEhInstance, HINSTANCE, PWSTRpCmdLine, intnCmdShow) { HRESULThr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) { IFileOpenDialog *pFileOpen; // CreatetheFileOpenDialogobject. hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen)); if (SUCCEEDED(hr)) { // Show the Open dialog box. hr = pFileOpen->Show(NULL); // Getthe file namefromthedialog box. if (SUCCEEDED(hr)) { IShellItem *pItem; hr = pFileOpen->GetResult(&pItem); if (SUCCEEDED(hr)) { PWSTRpszFilePath; hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); // Display the file nametotheuser. if (SUCCEEDED(hr)) { MessageBox(NULL, pszFilePath, L"File Path", MB_OK); CoTaskMemFree(pszFilePath); } pItem->Release(); } } pFileOpen->Release(); } CoUninitialize(); } return 0; }

  4. #include<windows.h> #include<shobjidl.h> intWINAPIwWinMain(HINSTANCEhInstance, HINSTANCE, PWSTRpCmdLine, intnCmdShow) { HRESULThr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) { IFileOpenDialog *pFileOpen; // CreatetheFileOpenDialogobject. hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen)); if (SUCCEEDED(hr)) { // Show the Open dialog box. hr = pFileOpen->Show(NULL); // Getthe file namefromthedialog box. if (SUCCEEDED(hr)) { IShellItem *pItem; hr = pFileOpen->GetResult(&pItem); if (SUCCEEDED(hr)) { PWSTRpszFilePath; hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); // Display the file nametotheuser. if (SUCCEEDED(hr)) { MessageBox(NULL, pszFilePath, L"File Path", MB_OK); CoTaskMemFree(pszFilePath); } pItem->Release(); } } pFileOpen->Release(); } CoUninitialize(); } return 0; } HRESULThr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) { CoUninitialize(); }

  5. #include<windows.h> #include<shobjidl.h> intWINAPIwWinMain(HINSTANCEhInstance, HINSTANCE, PWSTRpCmdLine, intnCmdShow) { HRESULThr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) { IFileOpenDialog *pFileOpen; // CreatetheFileOpenDialogobject. hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen)); if (SUCCEEDED(hr)) { // Show the Open dialog box. hr = pFileOpen->Show(NULL); // Getthe file namefromthedialog box. if (SUCCEEDED(hr)) { IShellItem *pItem; hr = pFileOpen->GetResult(&pItem); if (SUCCEEDED(hr)) { PWSTRpszFilePath; hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); // Display the file nametotheuser. if (SUCCEEDED(hr)) { MessageBox(NULL, pszFilePath, L"File Path", MB_OK); CoTaskMemFree(pszFilePath); } pItem->Release(); } } pFileOpen->Release(); } CoUninitialize(); } return 0; } // CreatetheFileOpenDialogobject. hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen)); if (SUCCEEDED(hr)) { pFileOpen->Release(); }

  6. #include<windows.h> #include<shobjidl.h> intWINAPIwWinMain(HINSTANCEhInstance, HINSTANCE, PWSTRpCmdLine, intnCmdShow) { HRESULThr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) { IFileOpenDialog *pFileOpen; // CreatetheFileOpenDialogobject. hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen)); if (SUCCEEDED(hr)) { // Show the Open dialog box. hr = pFileOpen->Show(NULL); // Getthe file namefromthedialog box. if (SUCCEEDED(hr)) { IShellItem *pItem; hr = pFileOpen->GetResult(&pItem); if (SUCCEEDED(hr)) { PWSTRpszFilePath; hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); // Display the file nametotheuser. if (SUCCEEDED(hr)) { MessageBox(NULL, pszFilePath, L"File Path", MB_OK); CoTaskMemFree(pszFilePath); } pItem->Release(); } } pFileOpen->Release(); } CoUninitialize(); } return 0; } // Show the Open dialog box. hr = pFileOpen->Show(NULL); if (SUCCEEDED(hr)) { }

  7. #include<windows.h> #include<shobjidl.h> intWINAPIwWinMain(HINSTANCEhInstance, HINSTANCE, PWSTRpCmdLine, intnCmdShow) { HRESULThr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) { IFileOpenDialog *pFileOpen; // CreatetheFileOpenDialogobject. hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen)); if (SUCCEEDED(hr)) { // Show the Open dialog box. hr = pFileOpen->Show(NULL); // Getthe file namefromthedialog box. if (SUCCEEDED(hr)) { IShellItem *pItem; hr = pFileOpen->GetResult(&pItem); if (SUCCEEDED(hr)) { PWSTRpszFilePath; hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); // Display the file nametotheuser. if (SUCCEEDED(hr)) { MessageBox(NULL, pszFilePath, L"File Path", MB_OK); CoTaskMemFree(pszFilePath); } pItem->Release(); } } pFileOpen->Release(); } CoUninitialize(); } return 0; } IShellItem *pItem; hr = pFileOpen->GetResult(&pItem); if (SUCCEEDED(hr)) { pItem->Release(); }

  8. #include<windows.h> #include<shobjidl.h> intWINAPIwWinMain(HINSTANCEhInstance, HINSTANCE, PWSTRpCmdLine, intnCmdShow) { HRESULThr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) { IFileOpenDialog *pFileOpen; // CreatetheFileOpenDialogobject. hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen)); if (SUCCEEDED(hr)) { // Show the Open dialog box. hr = pFileOpen->Show(NULL); // Getthe file namefromthedialog box. if (SUCCEEDED(hr)) { IShellItem *pItem; hr = pFileOpen->GetResult(&pItem); if (SUCCEEDED(hr)) { PWSTRpszFilePath; hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); // Display the file nametotheuser. if (SUCCEEDED(hr)) { MessageBox(NULL, pszFilePath, L"File Path", MB_OK); CoTaskMemFree(pszFilePath); } pItem->Release(); } } pFileOpen->Release(); } CoUninitialize(); } return 0; } PWSTRpszFilePath; hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); // Display the file nametotheuser. if (SUCCEEDED(hr)) { MessageBox(NULL, pszFilePath, L"File Path", MB_OK); CoTaskMemFree(pszFilePath); }

  9. #pragmaonce namespaceWinRTComponentCpp { publicrefclassCalculatorsealed { public: Calculator(); intAdd(int a, int b); }; } #include"pch.h“ #include"Calculator.h" usingnamespaceWinRTComponentCpp; Calculator::Calculator(){} intCalculator::Add(inta, intb) { returna + b; }

  10. Provides simple and well-designed .NET APIs specifically tailored for development of Windows Store apps

  11. #include <iostream> usingnamespacestd; usingnamespacePlatform; intmain(Array<String^>^ args) { String^ message = "Hello World!"; wcout << message->Data() << endl; return0; }

  12. intmain(void); intmain(); intmain(intargc, char** argv); intmain(intargc, char* argv[]);

  13. namespaceCppCx { ref classMyRefClass sealed {}; ref structMyRefStruct sealed {}; value classMyValueClass sealed {}; value structMyValueStruct sealed {}; interface structIMyInterface {}; }

  14. namespaceLearningCppCx { refclassFoosealed { internal: Foo(Foo%other) { Console::WriteLine(__FUNCTION__"(Foo%);"); Data = other.Data; } public: Foo(Foo^ other) { Console::WriteLine(__FUNCTION__"(Foo^);"); Data = other->Data; } Foo() { Console::WriteLine(__FUNCTION__"();"); } voidPrint() { Console::WriteLine(Data); } propertyintData; private: ~Foo() { Console::WriteLine(__FUNCTION__"();"); } }; }

  15. [MTAThread] intmain() { usingnamespaceLearningCppCx; Console::WriteLine("-- One --"); Foo^ one = ref newFoo(); one->Data = 42; Console::WriteLine("-- Two --"); Foo^ two = ref newFoo(one); Console::WriteLine("-- Three --"); Foo^ three = ref newFoo(); three = one; Console::WriteLine("-- Four --"); Foo^ four(one); Console::WriteLine("-- Five --"); Foo five(*one); return0; }

  16. refclassMyRefClasssealed {}; refstructMyRefStructsealed {}; valueclassMyValueClasssealed {}; valuestructMyValueStructsealed {};

  17. usingnamespacePlatform; value classFoo { public: intValue; }; [MTAThread] intmain() { // instanciando um value type; Foo number; number.Value = 34; // boxing por atribuição Object^ boxed = number; // unboxing por cast Foo unboxed = safe_cast<Foo>(boxed); return0; }

  18. namespaceBoxingDemo { publicref classClass1 sealed { public: Class1(){} Platform::IBox<int>^ Multiply(Platform::IBox<int>^ a, Platform::IBox<int>^ b) { if(a == nullptr || b == nullptr) returnnullptr; else returnref newPlatform::Box<int>(a->Value * b->Value); } }; }

  19. interface classIFoo { voidA(); voidB(); }; interface classIA { voidF(); }; interface classIB { voidF(); }; ref classC : IA, IB { public: virtualvoidF1() = IA::F {}; virtualvoidF2() = IB::F {}; }

  20. interface IFoo { voidDoSomething(); }; refclassFoo : IFoo { virtualvoidDoSomething() = IFoo::DoSomething {} } [MTAThread] intmain() { auto f = refnewFoo(); IFoo^ if= f; f->DoSomething();  // BOOM; if->DoSomething(); // Funciona return0; }

  21. ref classFoo { Platform::String _name; public: property Platform::String^ Name { Platform::String^ get() { return_name; } voidset(Platform::String^ value) { _name = value; } } };

  22. namespaceCppCxDelegates { refclassFoo; publicdelegateString^ GetNameDelegate(Foo^ f); publicrefclassFoosealed { String^ _name; public: Foo() {} Foo(String^ name) { _name = name; } propertyString^ Name { String^ get() { return_name; } } }; } • [MTAThread] • intmain() • { • usingnamespaceCppCxDelegates; • auto instance = refnewFoo("Elemar"); • auto ldelegate = refnewGetNameDelegate( • [](Foo^ f){ returnf->Name; } • ); • auto lstr = ldelegate(instance); • wcout << lstr->Data() << endl; • return0; • }

  23. Platform::String^ Name { voidset(Platform::String^ value) { if(value->IsEmpty()) { throwrefnewPlatform::InvalidArgumentException(); } _name = value; } Platform::String^ get() { return_name; } }

  24. #include <amp.h> #include <iostream> intmain() { usingnamespacestd; usingnamespaceconcurrency; inta_data[] = {1, 2, 3, 4, 5}; intb_data[] = {6, 7, 8, 9,10}; intsum_data[5]; array_view<constint, 1> a(5, a_data); array_view<constint, 1> b(5, b_data); array_view<int, 1> sum(5, sum_data); sum.discard_data(); parallel_for_each(sum.extent, [=] (index<1> i) restrict(amp) { sum[i] = a[i] + b[i]; }); for(inti = 0; i < 5; i++) cout << sum[i] << "... "; return0; }

  25. Obrigado! http://elemarjr.net @elemarjr facebook.com/elemarjr github.com/elemarjr elemarjr@gmail.com

More Related