getCurrentApplicationUserModelId 函数 (appmodel.h)

获取当前进程的 应用程序用户模型 ID

语法

LONG GetCurrentApplicationUserModelId(
  [in, out] UINT32 *applicationUserModelIdLength,
  [out]     PWSTR  applicationUserModelId
);

参数

[in, out] applicationUserModelIdLength

输入时, applicationUserModelId 缓冲区的大小(以宽字符为单位)。 成功时,使用的缓冲区大小,包括 null 终止符。

[out] applicationUserModelId

指向接收应用程序用户模型 ID 的缓冲区的指针。

返回值

如果该函数成功,则返回 ERROR_SUCCESS。 否则,该函数将返回错误代码。 可能的错误代码包括以下内容。

返回代码 说明
APPMODEL_ERROR_NO_APPLICATION
进程没有应用程序标识。
ERROR_INSUFFICIENT_BUFFER
缓冲区不够大,无法保存数据。 所需大小由 applicationUserModelIdLength 指定。

注解

有关字符串大小限制的信息,请参阅 标识常量

示例

#define _UNICODE 1
#define UNICODE 1

#include <Windows.h>
#include <appmodel.h>
#include <malloc.h>
#include <stdio.h>

int __cdecl wmain()
{
    UINT32 length = 0;
    LONG rc = GetCurrentApplicationUserModelId(&length, NULL);
    if (rc != ERROR_INSUFFICIENT_BUFFER)
    {
        if (rc == APPMODEL_ERROR_NO_APPLICATION)
            wprintf(L"Desktop application\n");
        else
            wprintf(L"Error %d in GetCurrentApplicationUserModelId\n", rc);
        return 1;
    }

    PWSTR fullName = (PWSTR) malloc(length * sizeof(*fullName));
    if (fullName == NULL)
    {
        wprintf(L"Error allocating memory\n");
        return 2;
    }

    rc = GetCurrentApplicationUserModelId(&length, fullName);
    if (rc != ERROR_SUCCESS)
    {
        wprintf(L"Error %d retrieving ApplicationUserModelId\n", rc);
        return 3;
    }
    wprintf(L"%s\n", fullName);

    free(fullName);

    return 0;
}

要求

要求
目标平台 Windows
标头 appmodel.h
Library Kernel32.lib
DLL Kernel32.dll

另请参阅

GetApplicationUserModelId

GetCurrentPackageFullName