-
Notifications
You must be signed in to change notification settings - Fork 112
Update README.md & add sample snippets #1591
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
Conversation
jevansaks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thank you for taking the initiative to get this started. I've been wanting to have a place to add more examples for a while.
|
This also fixes #1259, I'll update the PR description. Edit: I see you already did. Thanks! :) |
| @@ -0,0 +1,188 @@ | ||
| # Code examples | ||
|
|
||
| When, for example, marshaling is enabled and `useSafeHandles` is `true`, the code can be different than that in C++. Here we show a few code examples of using CsWin32. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized, in reading this, that there's no SafeHandle examples. Could you include some? If not, I can do it as a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first sample uses SafeHandle
CsWin32/docfx/docs/Examples.md
Lines 30 to 45 in e58c957
| static void Main(string[] args) | |
| { | |
| SafeHandle hFile; | |
| Span<char> szBuf = stackalloc char[(int)PInvoke.MAX_PATH]; | |
| if (args.Length is not 1) | |
| { | |
| Console.WriteLine("This sample takes a file name as a parameter\n"); | |
| return; | |
| } | |
| hFile = PInvoke.CreateFile( | |
| args[0], | |
| (uint)GENERIC_ACCESS_RIGHTS.GENERIC_READ, | |
| FILE_SHARE_MODE.FILE_SHARE_READ, | |
| null, FILE_CREATION_DISPOSITION.OPEN_EXISTING, 0, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do it as a follow-up.
However, please feel free to update the changes as you like.
|
/azp run |
| * `SafeHandle`-types automatically generated. | ||
| * Generates xml documentation based on and links back to learn.microsoft.com | ||
| - [Getting started](https://microsoft.github.io/CsWin32/docs/getting-started.html) | ||
| - [Examples](https://microsoft.github.io/CsWin32/docs/examples.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URLs are case sensitive. Your Examples.md will produce Examples.html
| - [Examples](https://microsoft.github.io/CsWin32/docs/examples.html) | |
| - [Examples](https://microsoft.github.io/CsWin32/docs/Examples.html) |
As the title, I updated README.md and added sample snippets.
Please see the changes on GitHub too.
Resolves #1259