@@ -17,7 +17,7 @@ public partial class SharedStaticV1Ext
1717 /// <summary>
1818 /// The stored function pointer for the per-file progress callback from the Main Application.
1919 /// </summary>
20- internal static unsafe delegate * unmanaged [ Cdecl ] < InstallPerFileProgress * , void > PerFileProgressCallback ;
20+ internal static nint PerFileProgressCallbackAddr ;
2121
2222 /// <summary>
2323 /// Invokes the per-file progress callback if it has been registered by the Main Application.
@@ -26,17 +26,19 @@ public partial class SharedStaticV1Ext
2626 /// <param name="perFileTotalBytes">Total size of the current file.</param>
2727 public static unsafe void InvokePerFileProgress ( long perFileDownloadedBytes , long perFileTotalBytes )
2828 {
29- var callback = PerFileProgressCallback ;
30- if ( callback == null )
29+ if ( PerFileProgressCallbackAddr == nint . Zero )
30+ {
3131 return ;
32+ }
3233
34+ // Call the callback
3335 InstallPerFileProgress progress = new ( )
3436 {
3537 PerFileDownloadedBytes = perFileDownloadedBytes ,
3638 PerFileTotalBytes = perFileTotalBytes
3739 } ;
38-
39- callback ( & progress ) ;
40+ ( ( delegate * unmanaged [ Cdecl ] < ref readonly InstallPerFileProgress , void > )
41+ PerFileProgressCallbackAddr ) ( in progress ) ;
4042 }
4143}
4244
@@ -60,16 +62,16 @@ private static void InitExtension_Update5Exports()
6062 /// <summary>
6163 /// This method is an ABI proxy and installer for the Per-file Progress Callback functionality.
6264 /// </summary>
63- private static unsafe HResult SetPerFileProgressCallback ( nint perFileProgressCallback )
65+ private static HResult SetPerFileProgressCallback ( nint perFileProgressCallback )
6466 {
6567 if ( perFileProgressCallback == nint . Zero )
6668 {
67- PerFileProgressCallback = null ;
69+ PerFileProgressCallbackAddr = nint . Zero ;
6870 InstanceLogger . LogTrace ( "[SetPerFileProgressCallback] Per-file progress callback has been uninstalled" ) ;
6971 return HResult . Ok ;
7072 }
7173
72- PerFileProgressCallback = ( delegate * unmanaged [ Cdecl ] < InstallPerFileProgress * , void > ) perFileProgressCallback ;
74+ PerFileProgressCallbackAddr = perFileProgressCallback ;
7375 InstanceLogger . LogTrace ( "[SetPerFileProgressCallback] Per-file progress callback has been installed at address: 0x{Ptr:x8}" , perFileProgressCallback ) ;
7476 return HResult . Ok ;
7577 }
0 commit comments