GetCurrentApplicationUserModelId function (appmodel.h)

Gets the application user model ID for the current process.

Syntax

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

Parameters

[in, out] applicationUserModelIdLength

On input, the size of the applicationUserModelId buffer, in wide characters. On success, the size of the buffer used, including the null terminator.

[out] applicationUserModelId

A pointer to a buffer that receives the application user model ID.

Return value

If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes include the following.

Return code Description
APPMODEL_ERROR_NO_APPLICATION
The process has no application identity.
ERROR_INSUFFICIENT_BUFFER
The buffer is not large enough to hold the data. The required size is specified by applicationUserModelIdLength.

Remarks

For info about string size limits, see Identity constants.

Examples

#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;
}

Requirements

Requirement Value
Target Platform Windows
Header appmodel.h
Library Kernel32.lib
DLL Kernel32.dll

See also

GetApplicationUserModelId

GetCurrentPackageFullName