mirror of
https://github.com/modernw/AppInstallerForWin8.git
synced 2026-04-11 16:57:18 +10:00
添加项目文件。
This commit is contained in:
31
AppLauncher/AppLauncher.cpp
Normal file
31
AppLauncher/AppLauncher.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// AppLauncher.cpp : 定义 DLL 应用程序的导出函数。
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "AppLauncher.h"
|
||||
|
||||
HRESULT LaunchApp (LPCWSTR lpswStr, PDWORD pdwProcessId)
|
||||
{
|
||||
if (!lpswStr) return E_INVALIDARG;
|
||||
if (FAILED (CoInitializeEx (NULL, COINIT_APARTMENTTHREADED))) return E_INVALIDARG;
|
||||
std::wstring strAppUserModelId (L"");
|
||||
if (lpswStr) strAppUserModelId += lpswStr;
|
||||
CComPtr<IApplicationActivationManager> spAppActivationManager;
|
||||
HRESULT hrResult = E_INVALIDARG;
|
||||
if (!strAppUserModelId.empty ())
|
||||
{
|
||||
// Instantiate IApplicationActivationManager
|
||||
hrResult = CoCreateInstance (CLSID_ApplicationActivationManager, NULL, CLSCTX_LOCAL_SERVER, IID_IApplicationActivationManager, (LPVOID*)&spAppActivationManager);
|
||||
if (SUCCEEDED (hrResult))
|
||||
{
|
||||
// This call ensures that the app is launched as the foreground window
|
||||
hrResult = CoAllowSetForegroundWindow (spAppActivationManager, NULL);
|
||||
// Launch the app
|
||||
if (SUCCEEDED (hrResult))
|
||||
{
|
||||
hrResult = spAppActivationManager->ActivateApplication (strAppUserModelId.c_str (), NULL, AO_NONE, pdwProcessId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hrResult;
|
||||
}
|
||||
Reference in New Issue
Block a user