@@ -30,8 +30,11 @@ internal static extern int PrjStartVirtualizing(
3030 ref PRJ_CALLBACKS callbacks ,
3131 IntPtr instanceContext ,
3232 ref PRJ_STARTVIRTUALIZING_OPTIONS options ,
33- out IntPtr namespaceVirtualizationContext ) ;
33+ out SafeProjFsHandle namespaceVirtualizationContext ) ;
3434
35+ // PrjStopVirtualizing takes raw IntPtr (not SafeProjFsHandle) because it is
36+ // called from SafeProjFsHandle.ReleaseHandle(), where the SafeHandle is already
37+ // closed and cannot be marshaled. All other ProjFS APIs use SafeProjFsHandle.
3538#if NET7_0_OR_GREATER
3639 [ LibraryImport ( ProjFSLib ) ]
3740 internal static partial void PrjStopVirtualizing ( IntPtr namespaceVirtualizationContext ) ;
@@ -51,7 +54,7 @@ internal static partial int PrjWritePlaceholderInfo(
5154 [ DllImport ( ProjFSLib , CharSet = CharSet . Unicode , ExactSpelling = true ) ]
5255 internal static extern int PrjWritePlaceholderInfo (
5356#endif
54- IntPtr namespaceVirtualizationContext,
57+ SafeProjFsHandle namespaceVirtualizationContext,
5558 string destinationFileName ,
5659 ref PRJ_PLACEHOLDER_INFO placeholderInfo ,
5760 uint length ) ;
@@ -63,7 +66,7 @@ internal static partial int PrjWritePlaceholderInfo2(
6366 [ DllImport ( ProjFSLib , CharSet = CharSet . Unicode , ExactSpelling = true ) ]
6467 internal static extern int PrjWritePlaceholderInfo2 (
6568#endif
66- IntPtr namespaceVirtualizationContext,
69+ SafeProjFsHandle namespaceVirtualizationContext,
6770 string destinationFileName ,
6871 ref PRJ_PLACEHOLDER_INFO placeholderInfo ,
6972 uint placeholderInfoSize ,
@@ -76,7 +79,7 @@ internal static partial int PrjWritePlaceholderInfo2Raw(
7679 [ DllImport ( ProjFSLib , CharSet = CharSet . Unicode , ExactSpelling = true , EntryPoint = "PrjWritePlaceholderInfo2" ) ]
7780 internal static extern int PrjWritePlaceholderInfo2Raw (
7881#endif
79- IntPtr namespaceVirtualizationContext,
82+ SafeProjFsHandle namespaceVirtualizationContext,
8083 IntPtr destinationFileName ,
8184 IntPtr placeholderInfo ,
8285 uint placeholderInfoSize ,
@@ -89,7 +92,7 @@ internal static partial int PrjUpdateFileIfNeeded(
8992 [ DllImport ( ProjFSLib , CharSet = CharSet . Unicode , ExactSpelling = true ) ]
9093 internal static extern int PrjUpdateFileIfNeeded (
9194#endif
92- IntPtr namespaceVirtualizationContext,
95+ SafeProjFsHandle namespaceVirtualizationContext,
9396 string destinationFileName ,
9497 ref PRJ_PLACEHOLDER_INFO placeholderInfo ,
9598 uint length ,
@@ -103,7 +106,7 @@ internal static partial int PrjDeleteFile(
103106 [ DllImport ( ProjFSLib , CharSet = CharSet . Unicode , ExactSpelling = true ) ]
104107 internal static extern int PrjDeleteFile (
105108#endif
106- IntPtr namespaceVirtualizationContext,
109+ SafeProjFsHandle namespaceVirtualizationContext,
107110 string destinationFileName ,
108111 uint updateFlags ,
109112 out uint failureReason ) ;
@@ -146,7 +149,7 @@ internal static partial int PrjWriteFileData(
146149 [ DllImport ( ProjFSLib , ExactSpelling = true ) ]
147150 internal static extern int PrjWriteFileData (
148151#endif
149- IntPtr namespaceVirtualizationContext,
152+ SafeProjFsHandle namespaceVirtualizationContext,
150153 ref Guid dataStreamId ,
151154 IntPtr buffer ,
152155 ulong byteOffset ,
@@ -159,7 +162,7 @@ internal static partial IntPtr PrjAllocateAlignedBuffer(
159162 [ DllImport ( ProjFSLib , ExactSpelling = true ) ]
160163 internal static extern IntPtr PrjAllocateAlignedBuffer(
161164#endif
162- IntPtr namespaceVirtualizationContext ,
165+ SafeProjFsHandle namespaceVirtualizationContext ,
163166 UIntPtr size ) ;
164167
165168#if NET7_0_OR_GREATER
@@ -181,7 +184,7 @@ internal static partial int PrjCompleteCommand(
181184 [ DllImport ( ProjFSLib , ExactSpelling = true ) ]
182185 internal static extern int PrjCompleteCommand (
183186#endif
184- IntPtr namespaceVirtualizationContext,
187+ SafeProjFsHandle namespaceVirtualizationContext,
185188 int commandId ,
186189 int completionResult ,
187190 IntPtr extendedParameters ) ;
@@ -193,7 +196,7 @@ internal static partial int PrjCompleteCommandWithNotification(
193196 [ DllImport ( ProjFSLib , ExactSpelling = true , EntryPoint = "PrjCompleteCommand" ) ]
194197 internal static extern int PrjCompleteCommandWithNotification (
195198#endif
196- IntPtr namespaceVirtualizationContext,
199+ SafeProjFsHandle namespaceVirtualizationContext,
197200 int commandId ,
198201 int completionResult ,
199202 ref PRJ_COMPLETE_COMMAND_EXTENDED_PARAMETERS extendedParameters ) ;
@@ -209,7 +212,7 @@ internal static partial int PrjClearNegativePathCache(
209212 [ DllImport ( ProjFSLib , ExactSpelling = true ) ]
210213 internal static extern int PrjClearNegativePathCache (
211214#endif
212- IntPtr namespaceVirtualizationContext,
215+ SafeProjFsHandle namespaceVirtualizationContext,
213216 out uint totalEntryNumber ) ;
214217
215218 // ============================
@@ -306,7 +309,7 @@ internal static partial int PrjGetVirtualizationInstanceInfo(
306309 [ DllImport ( ProjFSLib , ExactSpelling = true ) ]
307310 internal static extern int PrjGetVirtualizationInstanceInfo (
308311#endif
309- IntPtr namespaceVirtualizationContext,
312+ SafeProjFsHandle namespaceVirtualizationContext,
310313 ref PRJ_VIRTUALIZATION_INSTANCE_INFO virtualizationInstanceInfo ) ;
311314
312315 // ============================
@@ -318,7 +321,7 @@ internal struct PRJ_CALLBACK_DATA
318321 {
319322 public uint Size ;
320323 public uint Flags ;
321- public IntPtr NamespaceVirtualizationContext ;
324+ public IntPtr namespaceVirtualizationContext ; // PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT (native handle, NOT SafeHandle)
322325 public int CommandId ;
323326 public Guid FileId ;
324327 public Guid DataStreamId ;
0 commit comments