@@ -6,7 +6,7 @@ namespace ExampleApp.MiniTerm.Native;
66/// <summary>
77/// PInvoke signatures for win32 process api
88/// </summary>
9- static class ProcessApi
9+ static partial class ProcessApi
1010{
1111 internal const uint EXTENDED_STARTUPINFO_PRESENT = 0x00080000 ;
1212
@@ -92,29 +92,33 @@ public readonly bool Equals(SECURITY_ATTRIBUTES other) =>
9292 public static bool operator != ( SECURITY_ATTRIBUTES left , SECURITY_ATTRIBUTES right ) => ! left . Equals ( right ) ;
9393 }
9494
95- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
95+ [ LibraryImport ( "kernel32.dll" , SetLastError = true ) ]
9696 [ return : MarshalAs ( UnmanagedType . Bool ) ]
97- internal static extern bool InitializeProcThreadAttributeList (
97+ internal static partial bool InitializeProcThreadAttributeList (
9898 nint lpAttributeList , int dwAttributeCount , int dwFlags , ref nint lpSize ) ;
9999
100- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
100+ [ LibraryImport ( "kernel32.dll" , SetLastError = true ) ]
101101 [ return : MarshalAs ( UnmanagedType . Bool ) ]
102- internal static extern bool UpdateProcThreadAttribute (
102+ internal static partial bool UpdateProcThreadAttribute (
103103 nint lpAttributeList , uint dwFlags , nint attribute , nint lpValue ,
104104 nint cbSize , nint lpPreviousValue , nint lpReturnSize ) ;
105105
106- [ DllImport ( "kernel32.dll" , CharSet = CharSet . Unicode ) ]
106+ // LibraryImport cannot be used here: STARTUPINFOEX contains non-blittable string fields (SYSLIB1051)
107+ #pragma warning disable SYSLIB1054 // Use 'LibraryImportAttribute' instead of 'DllImportAttribute'
108+ [ DllImport ( "kernel32.dll" , SetLastError = true , CharSet = CharSet . Unicode ) ]
107109 [ return : MarshalAs ( UnmanagedType . Bool ) ]
108110 internal static extern bool CreateProcess (
109111 string lpApplicationName , string lpCommandLine , ref SECURITY_ATTRIBUTES lpProcessAttributes ,
110112 ref SECURITY_ATTRIBUTES lpThreadAttributes , bool bInheritHandles , uint dwCreationFlags ,
111113 nint lpEnvironment , string lpCurrentDirectory , [ In ] ref STARTUPINFOEX lpStartupInfo ,
112114 out PROCESS_INFORMATION lpProcessInformation ) ;
115+ #pragma warning restore SYSLIB1054
113116
114- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
117+ [ LibraryImport ( "kernel32.dll" , SetLastError = true ) ]
115118 [ return : MarshalAs ( UnmanagedType . Bool ) ]
116- internal static extern bool DeleteProcThreadAttributeList ( nint lpAttributeList ) ;
119+ internal static partial bool DeleteProcThreadAttributeList ( nint lpAttributeList ) ;
117120
118- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
119- internal static extern bool CloseHandle ( nint hObject ) ;
121+ [ LibraryImport ( "kernel32.dll" , SetLastError = true ) ]
122+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
123+ internal static partial bool CloseHandle ( nint hObject ) ;
120124}
0 commit comments