mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-06-17 20:19:24 +00:00
winrt: Show some exceptions
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <codecvt>
|
||||
#include <strsafe.h>
|
||||
|
||||
#include <roapi.h>
|
||||
#include <windows.ui.notifications.h>
|
||||
@@ -38,6 +39,14 @@ widen(const std::string & to_widen)
|
||||
return converter.from_bytes(to_widen);
|
||||
}
|
||||
|
||||
static std::string
|
||||
narrow(const std::wstring & to_narrow)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.to_bytes(to_narrow);
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
__declspec (dllexport) void
|
||||
@@ -74,13 +83,34 @@ extern "C"
|
||||
}
|
||||
|
||||
__declspec (dllexport) int
|
||||
notification_backend_init (void)
|
||||
notification_backend_init (const char **error)
|
||||
{
|
||||
if (!notifier)
|
||||
notifier = ToastNotificationManager::CreateToastNotifier (L"HexChat.Desktop.Notify");
|
||||
try
|
||||
{
|
||||
if (!notifier)
|
||||
notifier = ToastNotificationManager::CreateToastNotifier (L"HexChat.Desktop.Notify");
|
||||
}
|
||||
catch (Platform::Exception ^ ex)
|
||||
{
|
||||
static char exc_message[1024];
|
||||
std::string tmp = narrow(std::wstring(ex->Message->Data()));
|
||||
if (SUCCEEDED(StringCchPrintfA(exc_message, _countof(exc_message), "Error (0x%x): %s", ex->HResult, tmp.c_str())))
|
||||
*error = exc_message;
|
||||
else
|
||||
*error = "Exception + error converting exception message.";
|
||||
return 0;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
*error = "Generic c++ exception.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (FAILED (Windows::Foundation::Initialize (RO_INIT_SINGLETHREADED)))
|
||||
{
|
||||
*error = "Error initializing Windows::Foundation.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user