Skip to content

Instantly share code, notes, and snippets.

@Biswa96

Biswa96/NotepadUWP.cpp

Last active Oct 17, 2019
Embed
What would you like to do?
New Notepad stub from Windows 10 Insider build 18963
#include <Windows.h>
#include <stdio.h>
#include <appmodel.h>
#include <inspectable.h>
#include <Shlwapi.h>
#ifdef _MSC_VER
#pragma comment(lib, "Ole32.lib")
#pragma comment(lib, "Shlwapi.lib")
#pragma comment(lib, "Shell32.lib")
#endif
static const GUID CLSID_DesktopAppxActivator = {
0x168EB462,
0x775F,
0x42AE,
{ 0x91, 0x11, 0xD7, 0x14, 0xB2, 0x30, 0x6C, 0x2E } };
static const GUID IID_DesktopAppxActivator = {
0x72E3A5B0,
0x8FEA,
0x485C,
{ 0x9F, 0x8B, 0x82, 0x2B, 0x16, 0xDB, 0xA1, 0x7F } };
/* COM class from twinui.dll */
class IDesktopAppxActivator : public IUnknown
{
public:
virtual HRESULT Activate(
const wchar_t *applicationUserModelId,
const wchar_t *packageRelativeExecutable,
const wchar_t *arguments,
void **processHandle) = 0;
virtual HRESULT ActivateWithOptions(
const wchar_t *applicationUserModelId,
const wchar_t *executable,
const wchar_t *arguments,
unsigned int options,
unsigned int parentProcessId,
void **processHandle) = 0;
virtual HRESULT ActivateWithOptionsAndArgs(
const wchar_t *applicationUserModelId,
const wchar_t *executable,
const wchar_t *arguments,
unsigned int options,
unsigned int parentProcessId,
IInspectable *activatedEventArgs,
void **processHandle) = 0;
};
bool WINAPI IsPackageinstalled(PCWSTR packageFamilyName)
{
unsigned int count = 0, bufferLength = 0;
long res = FindPackagesByPackageFamily(
packageFamilyName,
240,
&count,
nullptr,
&bufferLength,
nullptr,
nullptr);
if ((!res || res == ERROR_INSUFFICIENT_BUFFER) && count > 0)
return true;
return false;
}
HANDLE WINAPI LaunchCentennialAppWithParameters(PCWSTR applicationUserModelId)
{
HRESULT hRes;
class IDesktopAppxActivator *appxActivate = nullptr;
HANDLE processHandle = nullptr;
hRes = CoInitialize(nullptr);
hRes = CoCreateInstance(
CLSID_DesktopAppxActivator,
nullptr,
CLSCTX_INPROC_SERVER,
IID_DesktopAppxActivator,
(void **)&appxActivate);
const wchar_t *arguments = PathGetArgsW(GetCommandLineW());
hRes = appxActivate->Activate(
applicationUserModelId,
L"Notepad\\notepad.exe",
arguments,
&processHandle);
if (hRes == ERROR_INSTALL_PACKAGE_NOT_FOUND)
wprintf(L"%ls Package was not found.\n", applicationUserModelId);
appxActivate->Release();
CoUninitialize();
return processHandle;
}
int WINAPI main(void)
{
HANDLE hProcess = NULL;
if (IsPackageinstalled(L"Microsoft.WindowsNotepad_8wekyb3d8bbwe"))
{
hProcess = LaunchCentennialAppWithParameters(L"Microsoft.WindowsNotepad_8wekyb3d8bbwe!App");
WaitForSingleObject(hProcess, INFINITE);
return 0;
}
if (IsPackageinstalled(L"Microsoft.WindowsNotepad.Dev_8wekyb3d8bbwe"))
{
hProcess = LaunchCentennialAppWithParameters(L"Microsoft.WindowsNotepad.Dev_8wekyb3d8bbwe!App");
WaitForSingleObject(hProcess, INFINITE);
return 0;
}
ShellExecuteW(
nullptr,
nullptr,
L"ms-windows-store://pdp/?PFN=Microsoft.WindowsNotepad_8wekyb3d8bbwe",
nullptr,
nullptr,
SW_SHOWNORMAL);
return 0;
}
@Biswa96

This comment has been minimized.

Copy link
Owner Author

@Biswa96 Biswa96 commented Aug 17, 2019

@WalkingCat small gift...

@WalkingCat

This comment has been minimized.

Copy link

@WalkingCat WalkingCat commented Aug 17, 2019

nice, thanks 👍

@Biswa96

This comment has been minimized.

Copy link
Owner Author

@Biswa96 Biswa96 commented Oct 17, 2019

@zodiacon Here is the trick in new notepad wrapper.

@zodiacon

This comment has been minimized.

Copy link

@zodiacon zodiacon commented Oct 17, 2019

Thanks for the tip!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment