【问题标题】:C++/WinRT UWP - HRESULT 0x80073D54 : The process has no package identityC++/WinRT UWP - HRESULT 0x80073D54:进程没有包标识
【发布时间】:2020-05-26 03:43:40
【问题描述】:

我正在为 UWP 使用 C++/WinRT。我正在尝试创建一个文件,但在第 11 行抛出异常:

#include "pch.h"

using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Storage;

IAsyncAction createFile()
{
    try
    {
        StorageFolder local{ ApplicationData::Current().LocalFolder() }; // line 11
        StorageFolder folder = co_await local.CreateFolderAsync(L"myapp", CreationCollisionOption::OpenIfExists);
        StorageFile file = co_await folder.CreateFileAsync(L"file", CreationCollisionOption::ReplaceExisting);

        co_await FileIO::WriteTextAsync(file, L"wide chars here.");
    }
    catch (const winrt::hresult_error& ex)
    {

    }
}

int main()
{
    init_apartment();
    createFile();
}

调试器没有向我显示错误,因为它崩溃了。输出显示

onecoreuap\base\appmodel\statemanager\winrt\lib\windows.storage.applicationdatafactory.server.cpp(126)\Windows.Storage.ApplicationData.dll!00007FFE8A7A1202: (caller: 00007FFE8A799081) ReturnHr(1) tid(3ad8) 80073D54 The process has no package identity.
onecoreuap\base\appmodel\statemanager\winrt\lib\windows.storage.applicationdatafactory.server.cpp(74)\Windows.Storage.ApplicationData.dll!00007FFE8A7990A9: (caller: 00007FF733954323) ReturnHr(2) tid(3ad8) 80073D54 The process has no package identity.
Debug Error!

Program: D:\Developpement\CPP\test\x64\Debug\Tests.exe

abort() has been called

我在谷歌上一无所获,那么这个错误是什么意思,我该如何解决?谢谢

【问题讨论】:

  • maincreateFile 中你不需要wait 吗?
  • 认为 main 中的调用应该是 createFile.get();wait 才能完成调用
  • 嗯,不是这样,.get() 也会出现错误
  • 这是一个错误,所以修复它。错误消息非常直接:您的应用程序没有包 ID。要么让它成为一个 UWP 应用程序,要么提供一个应用程序清单(虽然没有尝试过)。
  • 现在看起来很合乎逻辑......我怎样才能使它成为一个 UWP 应用程序,或者将清单链接到它?

标签: c++ uwp c++-winrt


【解决方案1】:

这里的问题在于 ApplicationData::Current()。 https://docs.microsoft.com/en-us/uwp/api/windows.storage.applicationdata.current?view=winrt-18362

获取当前应用程序信息的 API 基于应用程序的身份。任何 Windows 应用都可以具有标识(它不必是 UWP),但必须使用打包的安装程序来安装它(也称为 MSIX 安装程序)。您可以在此处了解有关打包的“完全信任”应用程序的更多信息: https://docs.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-prepare

您可以在此处使用桌面应用程序打包项目来更轻松地打包您的应用程序: https://docs.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-packaging-dot-net

话虽如此,如果你只是想在应用程序本地数据中打开一个文件,而不涉及打包问题,你可以根据 %appdata% 的位置创建文件夹。如果没有打包的安装程序,您有责任处理清理工作。

因此,将您的应用程序设置为打包应用程序在短期内需要做更多的工作,但如果这是您想要分发的东西,那么从长远来看,预先处理好这件事可能会为您节省大量工作.

如果您想手动设置应用程序文件夹,您可以按照以下方式开始:

int main()
{
    init_apartment();

    wstring appfolderstring;
    appfolderstring.resize(ExpandEnvironmentStrings(L"%AppData%", nullptr, 0));
    ExpandEnvironmentStringsW(L"%AppData%", &appfolderstring.front(), appfolderstring.size());
    wprintf(L"path: %ls!\n", appfolderstring.c_str());

    // Note: off-by-one issue... ExpandEnvironmentStringsW wants to write the final null character.
    // Leave buffer space to write it above, then trim it off here.
    appfolderstring.resize(appfolderstring.size()-1);

    StorageFolder folder{ StorageFolder::GetFolderFromPathAsync(appfolderstring).get() };
    printf("folder: %ls!\n", folder.DisplayName().c_str());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-15
    • 2016-12-14
    • 2016-04-02
    • 2016-07-29
    • 1970-01-01
    • 2019-11-21
    相关资源
    最近更新 更多