问题描述
我的第一个想法是使用 GetPackageFamilyName()
并寻找 ERROR_SUCCESS
与 APPMODEL_ERROR_NO_PACKAGE
.
My first thought was to use GetPackageFamilyName()
and look for ERROR_SUCCESS
vs APPMODEL_ERROR_NO_PACKAGE
.
但是,我需要支持 Windows 7,这使得 GetPackageFamilyName()
无法使用.
But, I need to support Windows 7, which makes GetPackageFamilyName()
unusable.
有没有像样的替代方法?也许注册表中有任何东西?
Is there a decent alternative method? Anything in the Registry, perhaps?
推荐答案
使用 GetProcAddress()
在运行时动态加载 GetPackageFamilyName()
,例如:
Use GetProcAddress()
to load GetPackageFamilyName()
dynamically at runtime, eg:
typedef LONG WINAPI (*LPFN_GPFN)(HANDLE, UINT32*, PWSTR);
bool bIsUWP = false;
LPFN_GPFN lpGetPackageFamilyName = (LPFN_GPFN) GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetPackageFamilyName");
if (lpGetPackageFamilyName)
{
UINT32 size = 0;
if (lpGetPackageFamilyName(GetCurrentProcess(), &size, NULL) == ERROR_INSUFFICIENT_BUFFER)
bIsUWP = true;
}
if (bIsUWP)
{
//...
}
else
{
//...
}
或者,考虑使用 GetCurentPackage...()
函数之一 (GetCurrentPackageFamilyName()
, GetCurrentPackageId()
, GetCurrentPackageInfo()
, etc) 而不是使用 GetPackageFamilyName()
带有 HANDLE
到调用进程.
Alternatively, consider using one of the GetCurentPackage...()
functions (GetCurrentPackageFamilyName()
, GetCurrentPackageId()
, GetCurrentPackageInfo()
, etc) instead of using GetPackageFamilyName()
with a HANDLE
to the calling process.
这篇关于确定 C++ 应用程序是否作为 UWP 应用程序运行,具有旧版支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!