dotnet-pinvoke

Generate P/Invoke and LibraryImport declarations from C/C++ headers for .NET.

Updated May 28, 2026
One-click install
npx skills add https://github.com/ojrojas/AgentsInstructions --skill dotnet-pinvoke-ojrojas
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-pinvoke
Source: https://github.com/ojrojas/AgentsInstructions/tree/main/.claude/skills/dotnet/skills/dotnet-pinvoke
Command: npx skills add https://github.com/ojrojas/AgentsInstructions --skill dotnet-pinvoke-ojrojas

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill simplifies the process of calling native (C/C++) libraries from .NET using P/Invoke and LibraryImport, ensuring accurate function signatures, proper string marshalling, and safe memory handling.

Core Features & Use Cases

  • P/Invoke Support: Write new P/Invoke or LibraryImport declarations from C/C++ headers.
  • Type Mapping: Map native types to .NET types with precision.
  • String Handling: Handle strings correctly with explicit encoding and memory ownership.
  • Error Handling: Manage errors effectively with appropriate flags and callbacks.
  • Use Case: When you need to wrap a C or C++ library for use in .NET, or when debugging crashes or memory leaks at the managed/native boundary.

Quick Start

Execute the dotnet-pinvoke skill to analyze the P/Invoke signature of the specified C/C++ header file.

Frequently Asked Questions about dotnet-pinvoke

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call native C/C++ libraries from .NET using P/Invoke?

To call native C/C++ libraries from .NET using P/Invoke, you define external methods with correct function signatures and marshal data types across the managed/native boundary. This Skill automates generating accurate P/Invoke declarations from C/C++ headers.

What is the best way to handle string marshalling and memory ownership in .NET interop?

Handling string marshalling and memory ownership in .NET interop requires explicit encoding specifications and safe memory allocation tracking. This Skill provides guidance on proper string handling and memory management to prevent leaks at the native boundary.

How do I map C/C++ native types to .NET types for native interop?

Mapping native types to .NET types for native interop involves translating C/C++ primitives and structures to their managed equivalents. This Skill ensures type mapping precision to maintain data integrity when integrating native libraries.

Does this P/Invoke guidance apply to both .NET Framework and .NET Core applications?

Yes, this P/Invoke guidance applies to both .NET Framework and .NET Core/5+ applications requiring native library integration. It supports writing both traditional P/Invoke and modern LibraryImport declarations.

Why does my .NET application crash or leak memory at the managed/native boundary?

Crashes or memory leaks at the managed/native boundary typically occur due to incorrect P/Invoke signatures, improper string marshalling, or mishandled memory ownership. This Skill helps debug these issues by ensuring accurate type mapping and safe error handling.

How do I use LibraryImport instead of P/Invoke for native library integration?

Using LibraryImport for native library integration involves creating source-generated declarations for calling unmanaged code. This Skill guides you in writing new LibraryImport declarations from C/C++ headers to efficiently interoperate with native libraries.