You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Desktop Bridge下LaunchFullTrustProcessForCurrentAppAsync调用失败(0x80010117)

解决Desktop Bridge打包Win32应用中LaunchFullTrustProcessForCurrentAppAsync的0x80010117错误

问题场景

基于Desktop Bridge打包的Win32应用中,通过Microsoft WRL调用LaunchFullTrustProcessForCurrentAppAsync启动控制台应用时失败,异步回调返回HRESULT=0x80010117,错误提示:

Call context cannot be accessed after call completed. CallContext: [\LaunchFullTrustProcessForApp] ...

相关代码实现

using namespace Microsoft::WRL;
using namespace ABI::Windows::ApplicationModel;

void LaunchFullTrustApp() {
        ComPtr<IFullTrustProcessLauncherStatics> fullTrustProcessLauncherStatic;
        auto hr = RoGetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_FullTrustProcessLauncher).Get(), __uuidof(fullTrustProcessLauncherStatic), &fullTrustProcessLauncherStatic);
        CheckHr(hr);

        auto onCompletedCallback = Callback<Implements<RuntimeClassFlags<ClassicCom>, IAsyncActionCompletedHandler, FtmBase>>(
            [](IAsyncAction* asyncInfo, AsyncStatus asyncStatus)
            {
                auto hr = asyncInfo->GetResults();
                CheckHr(hr); // hr = "0x80010117: Call context cannot be accessed after call completed. CallContext: [\LaunchFullTrustProcessForApp] ..."

                if (asyncStatus != AsyncStatus::Completed) { // asyncStatus = Error
                    return S_FALSE;
                }

                return S_OK;
            });


        ComPtr<IAsyncAction> launchAction;
        hr = fullTrustProcessLauncherStatic->LaunchFullTrustProcessForCurrentAppAsync(&launchAction);
        CheckHr(hr);

        hr = launchAction->put_Completed(onCompletedCallback.Get());
        CheckHr(hr);
    }

包清单配置

...
<Capabilities>
    <rescap:Capability Name="runFullTrust" />
</Capabilities>
...
<Extensions>
    <desktop:Extension Category="windows.fullTrustProcess" Executable="HelloWorld.exe" EntryPoint="Windows.FullTrustApplication" />
</Extensions>

错误原因

核心问题在于回调逻辑的执行顺序错误:在异步操作进入Error状态后,调用IAsyncAction::GetResults()会访问已被释放的调用上下文,从而触发0x80010117错误。当前代码先调用GetResults()再判断异步状态,导致错误场景下的无效访问。

修复方案

1. 调整回调逻辑顺序

先判断异步操作状态,仅当状态为AsyncStatus::Completed时才调用GetResults(),避免在错误状态下访问已释放的上下文。修改后的回调代码如下:

auto onCompletedCallback = Callback<Implements<RuntimeClassFlags<ClassicCom>, IAsyncActionCompletedHandler, FtmBase>>(
    [](IAsyncAction* asyncInfo, AsyncStatus asyncStatus)
    {
        if (asyncStatus != AsyncStatus::Completed) {
            // 获取错误代码并处理
            HRESULT errorHr;
            asyncInfo->get_ErrorCode(&errorHr);
            // 可添加错误日志、弹窗提示等逻辑
            return S_FALSE;
        }

        // 仅在成功完成时调用GetResults()
        auto hr = asyncInfo->GetResults();
        CheckHr(hr);

        return S_OK;
    });

2. 验证包清单配置

确保清单配置满足以下要求:

  • 根元素必须包含rescap和desktop命名空间声明,示例:
    <Package
      xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
      xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
      xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
      ...>
    
  • windows.fullTrustProcess扩展中的Executable路径必须正确,指向包内控制台应用的相对路径(如控制台在子目录需写SubFolder\HelloWorld.exe)
  • 确认runFullTrust权限已正确声明

3. 额外检查项

  • 控制台应用必须与主Win32应用同属一个Appx包,且已被正确包含在包内
  • 测试时需通过AppxPackage部署,不要直接运行未打包的exe文件

内容的提问来源于stack exchange,提问作者isrepeat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 02:50:27