-
Notifications
You must be signed in to change notification settings - Fork 413
Spec updates for GenerationId and Bootstrap C# API #1284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b4d838c
450d47b
a45fed2
c6b83e4
f4fee5d
2b4d2c3
bfcc9e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # Sample B.1 - HelloWorld console app using the Boostrap API | ||
|
|
||
| At runtime, HelloWorld wants to use the Windows App SDK Framework 1.0-preview1 package, so it calls the Bootstrap API. | ||
|
|
||
| ## Win32 | ||
|
|
||
| ```c++ | ||
| #include <iostream> | ||
|
|
||
| #include <MddBootstrap.h> | ||
|
|
||
| int main() | ||
| { | ||
| // Initialize access to Windows App SDK | ||
| const uint32_t c_majorMinorVersion{ 0x00010000 }; | ||
| PCWSTR c_versionTag{ L"preview1" }; | ||
DrusTheAxe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const PACKAGE_VERSION c_minVersion{}; | ||
| wprintf(L"MddBootstrapInitialize(0x%08X, \"%s\", %hu.%hu.%hu.%hu)...\n", | ||
| c_majorMinorVersion, c_versionTag, c_minVersion.Major, c_minVersion.Minor, c_minVersion.Build, c_minVersion.Revision); | ||
| HRESULT hr{ MddBootstrapInitialize(c_majorMinorVersion, c_versionTag, c_minVersion) }; | ||
| if (FAILED(hr)) | ||
| { | ||
| wprintf(L"Error 0x%X in MddBootstrapInitialize(0x%08X, \"%s\", %hu.%hu.%hu.%hu)\n", | ||
| hr, c_majorMinorVersion, c_versionTag, | ||
| c_minVersion.Major, c_minVersion.Minor, c_minVersion.Build, c_minVersion.Revision); | ||
| return hr; | ||
| } | ||
|
|
||
| // Do interesting stuff... | ||
| std::cout << "Hello World!\n"; | ||
|
|
||
| // Cleanup | ||
| MddBootstrapShutdown(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider showing adding a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed on the other PR, failure to call shutdown is a minor nit. Is automatic cleanup important? And if so, is that just a C++ thing or should we also provide it for C#?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good to show proper lifecycle behavior in a sample, even if someone chooses to not do it. Maybe a wrapper type for C# that implements IDisposable as a sample, so you can say "var winappsdkref = Bootstrap.Initialize()" or something
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I was thinking of IDisposable. Will cook something up Please check the related implementation PR #1274. Currently blocked by you. Feedback's been addressed. Would be helpful to get that and add this wrapper in a subsequent (smaller) PR than have it all await perfection. |
||
| return 0; | ||
| } | ||
| ``` | ||
|
|
||
| ## C# (Throw Exception on Error) | ||
|
|
||
| ```c# | ||
| using System; | ||
| using Microsoft.Windows.ApplicationModel.DynamicDependency; | ||
|
|
||
| namespace HelloWorldCS | ||
| { | ||
| class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| // Initialize access to Windows App SDK | ||
| uint majorMinorVersion = 0x00010000; | ||
| string versionTag = "preview1"; | ||
| var minVersion = new PackageVersion(); | ||
| try | ||
| { | ||
| Console.WriteLine($"Bootstrap.Initialize({majorMinorVersion:X08}, \"{versionTag}\", {minVersion.Major}.{minVersion.Minor}.{minVersion.Build}.{minVersion.Revision})..."); | ||
| Bootstrap.Initialize(majorMinorVersion, versionTag, minVersion); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.WriteLine(e.Message); | ||
| Environment.Exit(e.HResult); | ||
| } | ||
|
|
||
| // Do interesting stuff... | ||
| Console.WriteLine("Hello World!"); | ||
|
|
||
| // Cleanup | ||
| Bootstrap.Shutdown(); | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## C# (Return HRESULT on Error) | ||
DrusTheAxe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```c# | ||
| using System; | ||
| using Microsoft.Windows.ApplicationModel.DynamicDependency; | ||
|
|
||
| namespace HelloWorldCS_NoThrow | ||
| { | ||
| class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| // Initialize access to Windows App SDK | ||
| uint majorMinorVersion = 0x00010000; | ||
| string versionTag = "preview1"; | ||
| var minVersion = new PackageVersion(); | ||
| Console.WriteLine($"Bootstrap_NoThrow.Initialize({majorMinorVersion:X08}, \"{versionTag}\", {minVersion.Major}.{minVersion.Minor}.{minVersion.Build}.{minVersion.Revision})..."); | ||
| int hr = 0; | ||
| if (!Bootstrap.TryInitialize(majorMinorVersion, versionTag, minVersion, out hr)) | ||
| { | ||
| Console.WriteLine($"Error 0x{hr:X08} in Bootstrap_NoThrow.Initialize(0x{majorMinorVersion:X08}, \"{versionTag}\", {minVersion.Major}.{minVersion.Minor}.{minVersion.Build}.{minVersion.Revision})"); | ||
| Environment.Exit(hr); | ||
| } | ||
|
|
||
| // Do interesting stuff... | ||
| Console.WriteLine("Hello World!"); | ||
|
|
||
| // Cleanup | ||
| Bootstrap.Shutdown(); | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
Uh oh!
There was an error while loading. Please reload this page.