Add managed C#/VB declarations (DllImport + StructLayout) to PInvokeLib.dll reference article#52104
Add managed C#/VB declarations (DllImport + StructLayout) to PInvokeLib.dll reference article#52104
Conversation
…-invoke.md - Add StructLayout and DllImport managed type/function declarations - Create C# and VB snippet files for PInvokeLibManaged - Update article frontmatter with dev_langs and ai-usage Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
BillWagner
left a comment
There was a problem hiding this comment.
This looks good, and it's ready for final review.
There was a problem hiding this comment.
Pull request overview
This PR completes the PinvokeLib.dll example in marshalling-data-with-platform-invoke.md by adding the managed C# and Visual Basic declarations (struct mappings and DllImport signatures) that match the unmanaged header, and wiring those declarations into the article via snippet includes.
Changes:
- Added new C# and VB snippet projects containing managed
StructLayoutdeclarations andDllImportprototypes forPinvokeLib.dll. - Updated the article to include “Managed type declarations” and “Managed function prototypes” sections that reference the new snippet files.
- Updated article metadata (
ms.date,dev_langs, andai-usage).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/framework/interop/marshalling-data-with-platform-invoke.md | Adds new managed-declarations subsections and snippet includes; updates frontmatter metadata. |
| docs/framework/interop/snippets/marshalling-data-with-platform-invoke/csharp/PInvokeLibManaged/NativeMethods.cs | Introduces the C# StructLayout types and DllImport signatures for PinvokeLib.dll. |
| docs/framework/interop/snippets/marshalling-data-with-platform-invoke/csharp/PInvokeLibManaged/PInvokeLibManaged.csproj | Adds a minimal C# project to host/compile the snippet source. |
| docs/framework/interop/snippets/marshalling-data-with-platform-invoke/csharp/PInvokeLibManaged/Program.cs | Adds a minimal entry point for the snippet project. |
| docs/framework/interop/snippets/marshalling-data-with-platform-invoke/vb/PInvokeLibManaged/NativeMethods.vb | Introduces the VB StructLayout types and DllImport signatures for PinvokeLib.dll. |
| docs/framework/interop/snippets/marshalling-data-with-platform-invoke/vb/PInvokeLibManaged/PInvokeLibManaged.vbproj | Adds a minimal VB project to host/compile the snippet source. |
| docs/framework/interop/snippets/marshalling-data-with-platform-invoke/vb/PInvokeLibManaged/Program.vb | Adds a minimal entry point for the VB snippet project. |
|
|
||
| [!code-cpp[PInvokeLib#2](../../../samples/snippets/cpp/VS_Snippets_CLR/pinvokelib/cpp/pinvokelib.h#2)] | ||
|
|
||
| To call the library functions from managed code, first implement the managed prototypes for each function you want to invoke. | ||
| If the unmanaged code uses any custom types, you must also declare those types in your managed code. | ||
| Decorate the prototype with the <xref:System.Runtime.InteropServices.DllImportAttribute> attribute. | ||
| To call the library functions from managed code, implement managed prototypes for each function you want to invoke. If the unmanaged code uses any custom types, you must also declare those types in your managed code. Decorate each prototype with the <xref:System.Runtime.InteropServices.DllImportAttribute> attribute, and use <xref:System.Runtime.InteropServices.StructLayoutAttribute> to control the layout of managed structures so they match the unmanaged equivalents. |
There was a problem hiding this comment.
The section header is "PinvokeLib.dll", but the sentence immediately above this new paragraph still says the functions are provided by "Pinvoke.dll". Update that reference to "PinvokeLib.dll" so the library name is consistent throughout the section.
There was a problem hiding this comment.
@copilot change the text on line 58 to use "PInvokeLib.dll"
There was a problem hiding this comment.
Fixed in commit 2b6c51a — "Pinvoke.dll" is now "PInvokeLib.dll".
...rop/snippets/marshalling-data-with-platform-invoke/csharp/PInvokeLibManaged/NativeMethods.cs
Outdated
Show resolved
Hide resolved
...rop/snippets/marshalling-data-with-platform-invoke/csharp/PInvokeLibManaged/NativeMethods.cs
Outdated
Show resolved
Hide resolved
...k/interop/snippets/marshalling-data-with-platform-invoke/csharp/PInvokeLibManaged/Program.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
marshalling-data-with-platform-invoke.mdto include the C# and VB managed code sectionsOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Internal previews