GetCurrentApplicationUserModelId 函式 (appmodel.h)

取得目前進程 的應用程式使用者模型標識碼

語法

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

參數

[in, out] applicationUserModelIdLength

在輸入時, applicationUserModelId 緩衝區的大小會以寬字元表示。 成功時,使用的緩衝區大小,包括 Null 終止符。

[out] applicationUserModelId

接收應用程式使用者模型標識碼之緩衝區的指標。

傳回值

如果函式成功,它會傳回 ERROR_SUCCESS。 否則,函式會傳回錯誤碼。 可能的錯誤碼包括下列各項。

傳回碼 Description
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
程式庫 Kernel32.lib
DLL Kernel32.dll

另請參閱

GetApplicationUserModelId

GetCurrentPackageFullName