Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@0x5bfa
Copy link
Contributor

@0x5bfa 0x5bfa commented Dec 8, 2025

As the title, I updated README.md and added sample snippets.

Please see the changes on GitHub too.

Resolves #1259

Copy link
Member

@jevansaks jevansaks left a 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.

docfx/docs/toc.yml Show resolved Hide resolved
docfx/docs/Examples.md Outdated Show resolved Hide resolved
docfx/docs/Examples.md Outdated Show resolved Hide resolved
docfx/docs/Examples.md Outdated Show resolved Hide resolved
docfx/docs/Examples.md Outdated Show resolved Hide resolved
@jevansaks
Copy link
Member

jevansaks commented Dec 9, 2025

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.
Copy link
Member

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.

Copy link
Contributor Author

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

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);

Copy link
Contributor Author

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.

@jevansaks
Copy link
Member

/azp run

@jevansaks jevansaks enabled auto-merge (squash) December 9, 2025 17:34
@jevansaks jevansaks merged commit 48988ab into microsoft:main Dec 9, 2025
2 checks passed
@0x5bfa 0x5bfa deleted the 5bfa/docs branch December 9, 2025 18:39
* `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)
Copy link
Member

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

Suggested change
- [Examples](https://microsoft.github.io/CsWin32/docs/examples.html)
- [Examples](https://microsoft.github.io/CsWin32/docs/Examples.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide example code in repo / docs

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.