DesktopNotificationManagerCompat.cs CreateShotcut <T>Ошибка: чтение или запись в защищенную память - PullRequest
0 голосов
/ 02 марта 2020

Я собирался реализовать Windows10 Советы центра уведомлений, и мне нужно создать ярлык меню «Пуск».

Строка: использование (PropVariant toastid = new PropVariant (toastclass, VarEnum.VT_CLSID)) {ErrorHelper. VerifySucceeded (newShortcutProperties.SetValue (new PropertyKey (new Guid ("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 26), toastid)); Я получил исключение: «Попытки чтения или записи в защищенную память. Обычно это указывает на повреждение другой памяти». Что я должен делать

private static void CreatShortcut<T>(string shortcutPath) {

        String exePath = Process.GetCurrentProcess().MainModule.FileName;
        IShellLinkW newShortcut = (IShellLinkW)new CShellLink();

        ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));
        ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));

        IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

        using (PropVariant appId = new PropVariant(_aumid)) {
            ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(new PropertyKey(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 5), appId));
        }

        var toastclass = typeof(T).GUID.ToString();
        using (PropVariant toastid = new PropVariant(toastclass, VarEnum.VT_CLSID))  {
            ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(new PropertyKey(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 26), toastid));
        }
        ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());

        // Commit the shortcut to disk
        IPersistFile newShortcutSave = (IPersistFile)newShortcut;

        ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
    }
...