Skip to main content

System.Runtime.InteropServices by Microsoft

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: System.Runtime.InteropServices

Provides types that support COM interop and platform invoke services.

Commonly Used Types: System.Runtime.InteropServices.GCHandle System.Runtime.InteropServices.GuidAttribute System.Runtime.InteropServices.COMException System.DllNotFoundException System.Runtime.InteropServices.DllImportAttribute

Author: Microsoft

NuGet: https://www.nuget.org/packages/System.Runtime.InteropServices/

You can find more details at https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke-source-generation

Source : https://www.nuget.org/packages/System.Runtime.InteropServices/

Original Readme

note

About

note

Generate PInvoke calls

How to use

Example ( source csproj, source files )

This is the CSharp Project that references System.Runtime.InteropServices

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated/>
unsafe partial class DemoImport
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "7.0.10.6629")]
[System.Runtime.CompilerServices.SkipLocalsInitAttribute]
internal static partial int MessageBoxW_LI(nint hWnd, string lpText, string lpCaption, uint uType)
{
int __lastError;
int __retVal;
// Pin - Pin data in preparation for calling the P/Invoke.
fixed (void* __lpText_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(lpText))
fixed (void* __lpCaption_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(lpCaption))
{
System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
__retVal = __PInvoke(hWnd, (ushort*)__lpText_native, (ushort*)__lpCaption_native, uType);
__lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError();
}

System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
return __retVal;
// Local P/Invoke
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "MessageBoxW", ExactSpelling = true)]
static extern unsafe int __PInvoke(nint hWnd, ushort* lpText, ushort* lpCaption, uint uType);
}
}

Usefull

Download Example (.NET C# )

Share System.Runtime.InteropServices

https://ignatandrei.github.io/RSCG_Examples/v2/docs/System.Runtime.InteropServices

In the same category (EnhancementClass) - 27 other generators

ApparatusAOT

AspectGenerator

CommonCodeGenerator

CopyTo

DudNet

Enhanced.GetTypes

FastGenericNew

GeneratorEquals

HsuSgSync

Immutype

Ling.Audit

Lombok.NET

M31.FluentAPI

MemoryPack

Meziantou.Polyfill

Microsoft.Extensions.Logging

Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator

Microsoft.Interop.JavaScript.JSImportGenerator

OptionToStringGenerator

QueryStringGenerator

RSCG_Decorator

RSCG_UtilityTypes

StaticReflection

SyncMethodGenerator

System.Text.RegularExpressions

TelemetryLogging

ThisClass