Fungsi GetCurrentApplicationUserModelId (appmodel.h)

Mendapatkan ID model pengguna aplikasi untuk proses saat ini.

Sintaks

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

Parameter

[in, out] applicationUserModelIdLength

Pada input, ukuran buffer applicationUserModelId , dalam karakter yang luas. Jika berhasil, ukuran buffer yang digunakan, termasuk terminator null.

[out] applicationUserModelId

Penunjuk ke buffer yang menerima ID model pengguna aplikasi.

Menampilkan nilai

Jika fungsi berhasil, fungsi akan mengembalikan ERROR_SUCCESS. Jika tidak, fungsi mengembalikan kode kesalahan. Kode kesalahan yang mungkin mencakup yang berikut ini.

Menampilkan kode Deskripsi
APPMODEL_ERROR_NO_APPLICATION
Proses ini tidak memiliki identitas aplikasi.
ERROR_INSUFFICIENT_BUFFER
Buffer tidak cukup besar untuk menyimpan data. Ukuran yang diperlukan ditentukan oleh applicationUserModelIdLength.

Keterangan

Untuk informasi tentang batas ukuran string, lihat Konstanta identitas.

Contoh

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

Persyaratan

Persyaratan Nilai
Target Platform Windows
Header appmodel.h
Pustaka Kernel32.lib
DLL Kernel32.dll

Lihat juga

GetApplicationUserModelId

GetCurrentPackageFullName