commit ec826271a616ba89de863097420ee259bf987b09
parent c3fe500c5a3b13325de906947799b8986cb4b32f
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Mon, 13 Mar 2023 12:59:28 +0800
c-lib: delete main
We won't be executing this code as a standalone executable,
so let's delete such code.
Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Diffstat:
1 file changed, 0 insertions(+), 285 deletions(-)
diff --git a/internal/c-lib/toast.c b/internal/c-lib/toast.c
@@ -506,291 +506,6 @@ GenerateToast()
return;
}
-int main(int argc, char** argv)
-{
- HRESULT hr = S_OK;
- Impl_IGeneric* pClassFactory = NULL;
- BOOL bOk = FALSE;
- dwMainThreadId = GetCurrentThreadId();
- BOOL bInvokedFromToast = (argc > 1);
-
- /*
- * Initialize COM and Windows Runtime on this thread. Make sure that the threading models of the two match.
- */
- if (SUCCEEDED(hr))
- {
- hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
- } else {
- printf("failed to");
- }
-
- if (SUCCEEDED(hr))
- {
- hr = RoInitialize(RO_INIT_MULTITHREADED);
- } else {
- printf("failed to roinitialize\n");
- }
-
- /*
- * Allocate class factory. This factory produces our implementation of the INotificationActivationCallback interface.
- * This interface has an ::Activate member method that gets called when someone interacts with the toast notification.
- */
- if (SUCCEEDED(hr))
- {
- if (!(pClassFactory = malloc(sizeof(Impl_IGeneric)))) hr = E_OUTOFMEMORY;
- else
- {
- pClassFactory->lpVtbl = &Impl_IClassFactory_Vtbl;
- pClassFactory->dwRefCount = 1;
- }
- } else {
- printf("failed to allocate our IGeneric class factory\n");
- }
-
- /*
- * Instead of having to register our COM class in the registry beforehand, we opt to registering it at runtime;
- * we associate our GUID with the class factory that provides our INotificationActivationCallback interface.
- */
- DWORD dwCookie = 0;
- if (SUCCEEDED(hr))
- {
- hr = CoRegisterClassObject(&GUID_Impl_INotificationActivationCallback, pClassFactory, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &dwCookie);
- } else {
- printf("failed to register notification activation callback\n");
- }
-
- /*
- * Construct the path to our EXE that will be used to launch it when something requests our interface.
- * As said above, registration is dynamic - as long as this app runs, COM knows about the fact that this
- * app implements our INotificationActivationCallback interface. The info here is used when this app has
- * closed and someone clicks the toast notification for example; in that case, since our app is not
- * running, thus CoRegisterClassObject was not called, COM needs info on what EXE contains the implementation
- * of the interface, and we specify that here; without setting this, clicking on notifications will do nothing
- */
- wchar_t wszExePath[MAX_PATH + 100];
- ZeroMemory(wszExePath, MAX_PATH + 100);
- if (SUCCEEDED(hr))
- {
- hr = (GetModuleFileNameW(NULL, wszExePath + 1, MAX_PATH) != 0 ? S_OK : E_FAIL);
- } else {
- printf("failed to get module file\n");
- }
-
- if (SUCCEEDED(hr))
- {
- wszExePath[0] = L'"';
- wcscat_s(wszExePath, MAX_PATH + 100, L"\" " _T(TOAST_ACTIVATED_LAUNCH_ARG));
- }
-
- if (SUCCEEDED(hr))
- {
- hr = HRESULT_FROM_WIN32(RegSetValueW(HKEY_CURRENT_USER, L"SOFTWARE\\Classes\\CLSID\\{" _T(GUID_Impl_INotificationActivationCallback_Textual) L"}\\LocalServer32", REG_SZ, wszExePath, wcslen(wszExePath) + 1));
- } else {
- printf("failed to set registery value CLSID\n");
- }
-
- /*
- * Here we set some info about our app and associate our AUMID with the GUID from above
- * (the one that is associated with our class factory which produces our INotificationActivationCallback interface)
- */
- if (SUCCEEDED(hr))
- {
- hr = HRESULT_FROM_WIN32(RegSetKeyValueW(HKEY_CURRENT_USER, L"SOFTWARE\\Classes\\AppUserModelId\\" APP_ID, L"DisplayName", REG_SZ, L"Toast Activator Pure C Example", 31 * sizeof(wchar_t)));
- } else {
- printf("failed to set registery value AppUserModelId DisplayName\n");
- }
-
- if (SUCCEEDED(hr))
- {
- hr = HRESULT_FROM_WIN32(RegSetKeyValueW(HKEY_CURRENT_USER, L"SOFTWARE\\Classes\\AppUserModelId\\" APP_ID, L"IconBackgroundColor", REG_SZ, L"FF00FF00", 9 * sizeof(wchar_t)));
- } else {
- printf("failed to set registery value AppUserModelId IconBackgroundColor\n");
- }
-
- if (SUCCEEDED(hr))
- {
- hr = HRESULT_FROM_WIN32(RegSetKeyValueW(HKEY_CURRENT_USER, L"SOFTWARE\\Classes\\AppUserModelId\\" APP_ID, L"CustomActivator", REG_SZ, L"{" _T(GUID_Impl_INotificationActivationCallback_Textual) L"}", 39 * sizeof(wchar_t)));
- } else {
- printf("failed to set registery value AppUserModelId CustomActivator\n");
- }
-
- /*
- * We will display a notification only when this app is launched standalone (not by interacting with a notification)
- */
- HSTRING_HEADER hshAppId;
- HSTRING hsAppId = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = WindowsCreateStringReference(APP_ID, wcslen(APP_ID), &hshAppId, &hsAppId);
- } else {
- printf("failed to create string reference for app id\n");
- }
-
- HSTRING_HEADER hshToastNotificationManager;
- HSTRING hsToastNotificationManager = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = WindowsCreateStringReference(
- RuntimeClass_Windows_UI_Notifications_ToastNotificationManager,
- (UINT32)wcslen(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager),
- &hshToastNotificationManager, &hsToastNotificationManager
- );
- } else {
- printf("failed to create string reference for ToastNotificationManager runtime class: %x\n", hr);
- }
-
- __x_ABI_CWindows_CUI_CNotifications_CIToastNotificationManagerStatics* pToastNotificationManager = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = RoGetActivationFactory(hsToastNotificationManager, &IID_IToastNotificationManagerStatics, (LPVOID*)&pToastNotificationManager);
- } else {
- printf("failed to RoGetActivcationFactory for ToastNotificationManagerStatics\n");
- }
-
- __x_ABI_CWindows_CUI_CNotifications_CIToastNotifier* pToastNotifier = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = pToastNotificationManager->lpVtbl->CreateToastNotifierWithId(pToastNotificationManager, hsAppId, &pToastNotifier);
- } else {
- printf("failed to CreateToastNotifierWithId\n");
- }
-
- HSTRING_HEADER hshToastNotification;
- HSTRING hsToastNotification = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = WindowsCreateStringReference(RuntimeClass_Windows_UI_Notifications_ToastNotification, (UINT32)wcslen(RuntimeClass_Windows_UI_Notifications_ToastNotification), &hshToastNotification, &hsToastNotification);
- } else {
- printf("failed to create string reference for ToastNotification\n");
- }
-
- __x_ABI_CWindows_CUI_CNotifications_CIToastNotificationFactory* pNotificationFactory = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = RoGetActivationFactory(hsToastNotification, &IID_IToastNotificationFactory, (LPVOID*)&pNotificationFactory);
- } else {
- printf("failed to RoGetActivationFactory ToastNotification\n");
- }
-
- HSTRING_HEADER hshXmlDocument;
- HSTRING hsXmlDocument = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = WindowsCreateStringReference(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument, (UINT32)wcslen(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument), &hshXmlDocument, &hsXmlDocument);
- }
-
- HSTRING_HEADER hshBanner;
- HSTRING hsBanner = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = WindowsCreateStringReference(wszBannerText, (UINT32)wcslen(wszBannerText), &hshBanner, &hsBanner);
- }
-
- IInspectable* pInspectable = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = RoActivateInstance(hsXmlDocument, &pInspectable);
- }
-
- __x_ABI_CWindows_CData_CXml_CDom_CIXmlDocument* pXmlDocument = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = pInspectable->lpVtbl->QueryInterface(pInspectable, &IID_IXmlDocument, &pXmlDocument);
- }
-
- __x_ABI_CWindows_CData_CXml_CDom_CIXmlDocumentIO* pXmlDocumentIO = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = pXmlDocument->lpVtbl->QueryInterface(pXmlDocument, &IID_IXmlDocumentIO, &pXmlDocumentIO);
- }
-
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = pXmlDocumentIO->lpVtbl->LoadXml(pXmlDocumentIO, hsBanner);
- }
-
- __x_ABI_CWindows_CUI_CNotifications_CIToastNotification* pToastNotification = NULL;
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = pNotificationFactory->lpVtbl->CreateToastNotification(pNotificationFactory, pXmlDocument, &pToastNotification);
- }
-
- if (SUCCEEDED(hr) && !bInvokedFromToast)
- {
- hr = pToastNotifier->lpVtbl->Show(pToastNotifier, pToastNotification);
- }
-
- if (SUCCEEDED(hr))
- {
- MSG msg;
- while (GetMessageW(&msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&msg);
- DispatchMessageW(&msg);
- }
- }
-
- if (pToastNotification)
- {
- pToastNotification->lpVtbl->Release(pToastNotification);
- }
- if (pXmlDocumentIO)
- {
- pXmlDocumentIO->lpVtbl->Release(pXmlDocumentIO);
- }
- if (pXmlDocument)
- {
- pXmlDocument->lpVtbl->Release(pXmlDocument);
- }
- if (pInspectable)
- {
- pInspectable->lpVtbl->Release(pInspectable);
- }
- if (hsBanner)
- {
- WindowsDeleteString(hsBanner);
- }
- if (hsXmlDocument)
- {
- WindowsDeleteString(hsXmlDocument);
- }
- if (pNotificationFactory)
- {
- pNotificationFactory->lpVtbl->Release(pNotificationFactory);
- }
- if (hsToastNotification)
- {
- WindowsDeleteString(hsToastNotification);
- }
- if (pToastNotifier)
- {
- pToastNotifier->lpVtbl->Release(pToastNotifier);
- }
- if (pToastNotificationManager)
- {
- pToastNotificationManager->lpVtbl->Release(pToastNotificationManager);
- }
- if (hsToastNotificationManager)
- {
- WindowsDeleteString(hsToastNotificationManager);
- }
- if (hsAppId)
- {
- WindowsDeleteString(hsAppId);
- }
- if (dwCookie)
- {
- CoRevokeClassObject(dwCookie);
- }
- if (pClassFactory)
- {
- pClassFactory->lpVtbl->Release(pClassFactory);
- }
- RoUninitialize();
- CoUninitialize();
-
- return 0;
-}
// These are just testing the callback functionality.
// We can provide go callbacks to the DLL!