Error with suppressing icon in Windows tray area on Notification message via wxWidgets

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 13:54:58

问题


I have a C++ wxWidgets application wherein I am trying suppress the additional icon that pops up in the tray area when I need to display a notification (toast) message to the user.

To do this, I need to call wxNotificationMessage::MSWUseToasts which under Windows 10 will suppress that icon.

The parameters to that function call are a shortcut file path and the application user model id.

Looking at the implementation of how wxWidgets does Toast Notification, the shortcut will have the lnk extension added as well the absolute path added to it. So for the parameter I am merely passing the application name as a string.

For the second parameter, as per Microsoft's docs, it is like so "MyCompany.MyApp".

This function returns a bool which returns false when called with two parameters. But if I call the function with one parameter, it returns true. The error below happens with both cases.

I am using Inno Setup to install my application and I am setting the AppUserModelID:

[Icons]
Name: "{group}\MyApp"; Filename: "{app}\MyApp.exe"; AppUserModelID: "MyCompany.MyApp"
Name: "{autodesktop}\MyApp"; Filename: "{app}\MyApp.exe"; AppUserModelID: "MyCompany.MyApp"

Thus when I call the method MSWUseToasts everything works as expected, but when I close my application I'm basically getting a COM pointer exception, specifically from wxWidgets wxCOMPtr. The exception is:

Exception thrown: read access violation.
wxToastNotifMsgImpl::ms_toastMgr.m_ptr->**** was 0x78F253C0. occurred

Visual Studio breaks on the error in the file comptr.h here:

void reset(T* ptr = NULL)
{
    if ( m_ptr != ptr)
    {
        if ( ptr )
            ptr->AddRef();
        if ( m_ptr )
            m_ptr->Release(); // error occurs here
        m_ptr = ptr;
    }
}

I don't know enough about COM nor how the toast notifications work behind the scenes which are abstracted away by wxWidgets to know what the exact issue is.

Addendum:

With some Googling, I did find this from an existing StackOverflow answer. I used the last link posted in the answer to here where I copy-pasted the code posted at the end of the document into a executable and ran it against the PID of application and for my process it returns APPMODEL_ERROR_NO_APPLICATION which means The process has no application identity. Not sure if that might correlate to my issue. Googling that error only yields results for issues relating to "no package identity"

来源:https://stackoverflow.com/questions/61193724/error-with-suppressing-icon-in-windows-tray-area-on-notification-message-via-wxw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!