我正在开发一个 qt5 windows 11 应用程序,我希望能够请求用户将其固定到任务栏,使用我请求的 winRT 语言投影和当前任务栏的实例,它崩溃了,但出现以下异常:
onecoreuap ase ppmodel iledatarepository iledevapi\src Askbarmanagerimpl.cpp(111)\wpnapps.dll!00007FFA67F1B526: (调用者: 00007FFA67F1B3B1) 异常(2) tid(7350) 80070005 访问被拒绝。
知道我能做些什么来解决这个问题吗?
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <Windows.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.UI.Shell.h>
#include <iostream>
namespace winrt
{
using namespace Windows::UI::Shell;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
try
{
auto taskbarManager = winrt::TaskbarManager::GetDefault(); // <- exception here
if (taskbarManager.IsSupported())
{
taskbarManager.RequestPinCurrentAppAsync().get();
}
}
catch (const winrt::hresult_error &error)
{
std::cerr << error.message().c_str() << std::endl;
}
}
#include "mainwindow.h"
#include <QApplication>
#include <winrt/base.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
winrt::uninit_apartment();
winrt::init_apartment();
MainWindow w;
w.show();
return a.exec();
}
最后我成功地通过解锁功能使其在打包的应用程序中工作:
auto result = winrt::Windows::ApplicationModel::LimitedAccessFeatures::TryUnlockFeature(c_lafFeature, c_lafToken, c_lafAttestation);
if (result.Status() == winrt::Windows::ApplicationModel::LimitedAccessFeatureStatus::Available ||
result.Status() == winrt::Windows::ApplicationModel::LimitedAccessFeatureStatus::AvailableWithoutToken)
{
auto taskbarManager = winrt::Windows::UI::Shell::TaskbarManager::GetDefault();
if (taskbarManager.IsSupported() && taskbarManager.IsPinningAllowed() &&
!taskbarManager.IsCurrentAppPinnedAsync().get())
{
taskbarManager.RequestPinCurrentAppAsync().get();
}
}