Use g_new0 and g_free to generate raw strings
This commit is contained in:
parent
94944a9e2a
commit
8856fcbceb
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
std::wstring sview_to_wstr(const std::string_view str);
|
std::wstring sview_to_wstr(const std::string_view str);
|
||||||
char* wsview_to_char(const std::wstring_view wstr);
|
gchar* wsview_to_char(const std::wstring_view wstr);
|
|
@ -10,7 +10,7 @@ char* wsview_to_char(const std::wstring_view wstr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
int final_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), nullptr, 0, nullptr, nullptr);
|
int final_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), nullptr, 0, nullptr, nullptr);
|
||||||
char* strTo = new char[final_size + 1]{ 0 };
|
gchar* strTo = g_new0(gchar, final_size + 1);
|
||||||
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), strTo, final_size, nullptr, nullptr);
|
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), strTo, final_size, nullptr, nullptr);
|
||||||
return strTo;
|
return strTo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,7 +270,9 @@ winrtEventToken* winrt_windows_ui_notifications_toast_notification_Activated(win
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(wsview_to_char(arguments), nullptr /* user_input */ , 0 /* user_input.size() */, context);
|
auto args = wsview_to_char(arguments);
|
||||||
|
callback_data->callback(args, nullptr /* user_input */ , 0 /* user_input.size() */, callback_data->context);
|
||||||
|
g_free(args);
|
||||||
});
|
});
|
||||||
callback_data->SetToken(winrt_event_token_new_from_token(&token));
|
callback_data->SetToken(winrt_event_token_new_from_token(&token));
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ gboolean winrt_InitApartment()
|
||||||
{
|
{
|
||||||
auto message = wsview_to_char(e.message());
|
auto message = wsview_to_char(e.message());
|
||||||
std::cerr << message << '\n';
|
std::cerr << message << '\n';
|
||||||
delete[] message;
|
g_free(message);
|
||||||
if (e.code() == -2147417850 /* RPC_E_CHANGED_MODE */) // harmless
|
if (e.code() == -2147417850 /* RPC_E_CHANGED_MODE */) // harmless
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue