[XAP][SOURCE] Native Toast Notification Launcher

compu829

Senior Member
Nov 5, 2006
349
301
0
Hey Guys,

I think I know why it isn't working anymore...In WP8, CShellCromeAPI.dll only had an entrypoint called "Shell_PostMessageToast". In the WP 8.1 version there are 3 entrypoints: "Shell_PostMessageToast", "Shell_PostMessageToast2", and "Shell_RaiseToastNotifications".

I am guessing that starting with WP 8.1 it is now a 2-step process. You call "Shell_PostMessageToast" to put it on the stack, and then you call "Shell_RaiseToastNotifications" to fire them. It could also be as simple as replacing "Shell_PostMessageToast" with "Shell_PostMessageToast2". This is only speculation, but I can't test it as I only have a Windows 7 rig at work, so I can't compile against the WP 8.1 SDK.

If anyone with Visual Studio 2013 and Windows 8.1 with the WP 8.1 SDK installed wants to retarget the solution, we might be able to get it working again.
 

compu829

Senior Member
Nov 5, 2006
349
301
0
Downloading now! Unfortunately, My HTC 8x doesn't have 8.1 GDR1 on it, so hopefully it won't complain too much :p

*EDIT*

So I got it installed, but VIsual Studio 2013 will let me change the platform, but as soon as I retarget it to "Windows phone 8.1" it refuses to load the project saying "Windows 8.1 is required to load this project"

Guess I'm gunna have to manually "upgrade" the SDK...

*EDIT2* So the reason I am having so much trouble is we need an updated ShellChromeAPI.lib that goes along with the new WP 8.1 DLL. Anyone know where to find it? @cpuguy
 
Last edited:

compu829

Senior Member
Nov 5, 2006
349
301
0
@HD2Owner Thanks! I'll be in soon.

@snickler I created my own lib. For reference, here is how to generate libs from just a dll: http://adrianhenke.wordpress.com/2008/12/05/create-lib-file-from-dll/ The code compiles with my custom lib, however it crashes when I hit the "Toast" button while running on the device.

Crash output below:
Code:
{System.Runtime.InteropServices.COMException (0x8007007F): The specified procedure could not be found. (Exception from HRESULT: 0x8007007F)
   at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
   at CShellChromeAPI.ShellChrome..ctor()
   at NativeToastLauncher.Launcher..cctor()}
*Edit 2*
This method doesn't seem to work with windows phone :/

*edit 3*
I'm an idiot...I accidentally told the tool to export my lib as "ShellChrome.lib" and was manually renaming the output to "ShellChromeAPI.lib" After exporting with the proper name, the code no longer crashes, but no toasts just yet.
 
Last edited:

snickler

Retired Forum Moderator / Inactive Recognized Deve
Aug 17, 2010
1,320
1,130
0
Dub V
www.sinclairinat0r.com
@HD2Owner Thanks! I'll be in soon.

@snickler I created my own lib. For reference, here is how to generate libs from just a dll: http://adrianhenke.wordpress.com/2008/12/05/create-lib-file-from-dll/ The code compiles with my custom lib, however it crashes when I hit the "Toast" button while running on the device.

Crash output below:
Code:
{System.Runtime.InteropServices.COMException (0x8007007F): The specified procedure could not be found. (Exception from HRESULT: 0x8007007F)
   at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
   at CShellChromeAPI.ShellChrome..ctor()
   at NativeToastLauncher.Launcher..cctor()}
Ah HA! So that's how you generate libs. I was too lazy to actually research a way of doing that.
 

compu829

Senior Member
Nov 5, 2006
349
301
0
So according to the mappings I can see, the function (along with almost everything in the dll) reference something called
Code:
.data:1001C000 ___security_cookie dd 0BB40E64Eh
on another note, I found the following code randomly kicking around on my PC (I think it was from the leaked 8.1 SDK)

Code:
namespace Microsoft.Phone.Shell
{
    using System;
    using System.Runtime.InteropServices;
    using System.Security;

    internal class LocalNotificationInterop
    {
        internal const int LN_MAX_APP_BASE_URI_SIZE = 0x100;

        public LocalNotificationInterop()
        {
            base..ctor();
            return;
        }

        [SecuritySafeCritical, DllImport("PlatformInterop.dll")]
        internal static extern int LNGetAppTaskInfo(ref LNTaskInfo lnTaskInfo);
        [SecuritySafeCritical, DllImport("ShellChromeAPI.dll", EntryPoint="Shell_PostMessageToast")]
        internal static extern int SHPostMessageToast(ref MessageToastData mtData);

        [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
        internal struct LNTaskInfo
        {
            internal int IsAppInForeground;
            internal Guid ProductId;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=0x100)]
            internal string AppBaseUri;
        }

        [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode), SecuritySafeCritical]
        internal struct MessageToastData
        {
            public Guid ProductId;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string Title;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string Content;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string TaskUri;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string SoundFile;
            public MessageToastData(Guid productId, string taskUri)
            {
                this.ProductId = productId;
                this.TaskUri = taskUri;
                this.Title = "";
                this.Content = "";
                this.SoundFile = "";
                return;
            }
        }
    }
}
If anyone wants to try building that in 8.1, you may "get lucky" :) Don't forget to set the "ToastNotification" option to true in the manifest file!
 
  • Like
Reactions: snickler

GoodDayToDie

Inactive Recognized Developer
Jan 20, 2011
6,066
2,930
0
Seattle
The ___security_cookie field is for the stack canary check (buffer overflow protection). It's added by the /GS compiler option, and can be safely ignored unless you're working on an exploit that requires smashing the stack.
 

compu829

Senior Member
Nov 5, 2006
349
301
0
@GoodDayToDie Thanks for the info! That explains why it seemed like every call went through that :) I only saw that in the WP 8.1 implementation of the dll, granted I am comparing the x86 version from the emulator to the ARM version from an FFU.


***Update***

Whelp, using
Code:
[SecuritySafeCritical, DllImport("ShellChromeAPI.dll", EntryPoint = "Shell_PostMessageToast")]
        internal static extern int SHPostMessageToast(ref MessageToastData mtData);
in the WP 8.1 emulator results in our good friend "0x80070005" appearing :/
 
Last edited:

GoodDayToDie

Inactive Recognized Developer
Jan 20, 2011
6,066
2,930
0
Seattle
Well, there are capabilities to do so, but they aren't available to third-party devs. You'd need to be an OEM (or similarly privileged MS partner) or have an interop-unlocked phone to sideload an app with those capabilities.
@compu829: Do you still get that error if you specify the app which is actually popping the toast as the target *of* the toast?
 
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone