Help with DLLCall and getting information

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Ferry
Posts: 13
Joined: 10 Jul 2014, 15:55

Help with DLLCall and getting information

12 Apr 2023, 07:22

Hello,

I'm trying to make the first part of getting the buffer size of the GetCurrentApplicationUserModelId to work:
https://learn.microsoft.com/en-us/windows/win32/api/appmodel/nf-appmodel-getcurrentapplicationusermodelid

The second part already works if i set the buffersize manualy to an appropiate size like 256.
This is what i got so far but the output will be empty all the time. Even when starting from an MSIx environment.

Code: Select all


Length := 0
Length := Buffer(Length, 64)
RC := DllCall("GetCurrentApplicationUserModelId", "Ptr", Length, "UInt", 0)
Length := StrGet(Length)
MsgBox RC
MsgBox Length

This part is hard to test because the execution must take place within a AppX/MSIx environment to make it work. I got it sort of working using AutoHotKey 1 using VarSetCapacity and NumGet instead of Buffer and StrGet.

Here some information for C++

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.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Help with DLLCall and getting information

12 Apr 2023, 09:37

the MSDN code rewritten:

Code: Select all

#Requires AutoHotkey v2.0.2

rc := DllCall('GetCurrentApplicationUserModelId', 'UInt*', &length := 0, 'Ptr', 0)

ERROR_INSUFFICIENT_BUFFER := 122
APPMODEL_ERROR_NO_APPLICATION := 15703
if (rc != ERROR_INSUFFICIENT_BUFFER)
{
	if (rc = APPMODEL_ERROR_NO_APPLICATION)
		MsgBox("Desktop application\n")
	else
		MsgBox("Error " rc " in GetCurrentApplicationUserModelId\n")
	ExitApp(1)
}

sizeofwchar_t := 2

try
	fullName := Buffer(length * sizeofwchar_t)
catch MemoryError
{
	MsgBox("Error allocating memory\n")
	ExitApp(2)
}

rc := DllCall('GetCurrentApplicationUserModelId', 'UInt*', &length, 'Ptr', fullName)

ERROR_SUCCESS := 0
if (rc != ERROR_SUCCESS)
{
	MsgBox("Error " rc " retrieving ApplicationUserModelId\n")
	ExitApp(3)
}
MsgBox(StrGet(fullName))
Ferry
Posts: 13
Joined: 10 Jul 2014, 15:55

Re: Help with DLLCall and getting information

12 Apr 2023, 10:43

Thanks @swagfag! Tested it and it works like a charm.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Draken, Gewerd_Strauss and 38 guests