public LoaderNotification()
 {
     IntPtr context = IntPtr.Zero; // new IntPtr(12345);
     _notificationDelegate = Notification; // To prevent GC of the delegate
     var status = LdrRegisterDllNotification(0, _notificationDelegate, context, out _cookie);
     if (status != 0)
     {
         Debug.Print($"@@@@ LoaderNotification Result: {status}");
         throw new InvalidOperationException($"Error in LdrRegisterDlLNotification. Result: {status}");
     }
 }
        public LoaderNotification()
        {
            IntPtr context = IntPtr.Zero;         // new IntPtr(12345);

            _notificationDelegate = Notification; // To prevent GC of the delegate
            var status = LdrRegisterDllNotification(0, _notificationDelegate, context, out _cookie);

            if (status != 0)
            {
                Debug.Print($"@@@@ LoaderNotification Result: {status}");
                throw new InvalidOperationException($"Error in LdrRegisterDlLNotification. Result: {status}");
            }
        }
 static extern uint /*NtStatus*/ LdrRegisterDllNotification(
     uint flags, // This parameter must be zero.
     LdrNotification notificationFunction,
     IntPtr context,
     out IntPtr cookie);
 static extern uint LdrRegisterDllNotification(
     uint flags, // This parameter must be zero.
     LdrNotification notificationFunction, 
     IntPtr context, 
     out IntPtr cookie);