Files
raven/testdata/native_loader/winrt_import_client.c
T
Raymond Bennett 25a223eb04 fix: load the Windows Runtime component for programs that only import its activation
The shell component holds the Windows Runtime's activation (RoInitialize,
RoGetActivationFactory and friends), which combase and runtimeobject
forward to once it is loaded. It was loaded only for programs importing
COM, the shell or user32, so a program that imports just combase,
runtimeobject or the api-ms-win-core-winrt API sets got the placeholder
that registers no class, and activated nothing.

Assisted-by: Claude Code:claude-opus-5-5
AI-Scope: the loading condition, its comment and the winrt_import_client test
2026-10-30 08:17:33 -07:00

29 lines
1.2 KiB
C

#define WIN32_LEAN_AND_MEAN
#define INITGUID
#define CINTERFACE
#define COBJMACROS
#include <windows.h>
#include <winstring.h>
#include <roapi.h>
/* A program that imports only the Windows Runtime's activation and strings, through the API sets runtimeobject's import library names,
* and nothing of COM, the shell or user32: it activates the package manager by name and reads back its class name. */
int raven_entry(void)
{
static const WCHAR name[] = L"Windows.Management.Deployment.PackageManager";
HSTRING class_name = NULL, runtime_name = NULL;
IInspectable *object = NULL;
UINT32 length = 0;
if (FAILED(RoInitialize(RO_INIT_MULTITHREADED))) return 1;
if (WindowsCreateString(name, ARRAYSIZE(name) - 1, &class_name) != S_OK) return 2;
if (RoActivateInstance(class_name, &object) != S_OK || !object) return 3;
if (IInspectable_GetRuntimeClassName(object, &runtime_name) != S_OK) return 4;
const WCHAR *text = WindowsGetStringRawBuffer(runtime_name, &length);
if (length != ARRAYSIZE(name) - 1 || CompareStringOrdinal(text, (int)length, name, -1, FALSE) != CSTR_EQUAL) return 5;
WindowsDeleteString(runtime_name);
IInspectable_Release(object);
WindowsDeleteString(class_name);
RoUninitialize();
return 0;
}