Created
August 9, 2024 06:09
-
-
Save Aetopia/640b5f6f9d7a39decda05441112d1f92 to your computer and use it in GitHub Desktop.
COM Inheritance in C Win32.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <initguid.h> | |
#include <windows.h> | |
#include <shobjidl.h> | |
void $(const char *format, ...) | |
{ | |
va_list ArgList = NULL; | |
va_start(ArgList, format); | |
CHAR szOutput[1025] = {}; | |
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), szOutput, wvsprintfA(szOutput, format, ArgList), NULL, NULL); | |
va_end(ArgList); | |
} | |
HRESULT QueryInterface(IAppVisibilityEvents *This, REFIID riid, void **ppvObject) | |
{ | |
return RtlCompareMemory(riid, &IID_IAppVisibilityEvents, sizeof(IID)) == sizeof(IID) || | |
RtlCompareMemory(riid, &IID_IUnknown, sizeof(IID)) == sizeof(IID) | |
? !(*ppvObject = This) | |
: E_NOINTERFACE; | |
} | |
ULONG _(IAppVisibilityEvents *_) | |
{ | |
return 0; | |
} | |
HRESULT AppVisibilityOnMonitorChanged(IAppVisibilityEvents *This, HMONITOR hMonitor, | |
MONITOR_APP_VISIBILITY previousMode, MONITOR_APP_VISIBILITY currentMode) | |
{ | |
static INT _ = 0; | |
$("AppVisibilityOnMonitorChange: %d\n", ++_); | |
return S_OK; | |
} | |
HRESULT LauncherVisibilityChange(IAppVisibilityEvents *This, WINBOOL currentVisibleState) | |
{ | |
static INT _ = 0; | |
$("LauncherVisibilityChange: %d\n", ++_); | |
return S_OK; | |
} | |
int mainCRTStartup() | |
{ | |
CoInitialize(NULL); | |
IAppVisibility *pAppVisibility = NULL; | |
CoCreateInstance(&CLSID_AppVisibility, NULL, CLSCTX_INPROC_SERVER, &IID_IAppVisibility, (LPVOID *)&pAppVisibility); | |
pAppVisibility->lpVtbl->Advise( | |
pAppVisibility, | |
&((IAppVisibilityEvents){.lpVtbl = &((IAppVisibilityEventsVtbl){ | |
QueryInterface, _, _, AppVisibilityOnMonitorChanged, LauncherVisibilityChange})}), | |
&((DWORD){})); | |
MSG _ = {}; | |
while (GetMessageW(&_, NULL, 0, 0)) | |
DispatchMessageW(&_); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment