gpt4 book ai didi

visual-c++ - native c++ dll 如何检测它何时在 Windows 应用商店应用程序中运行

转载 作者:行者123 更新时间:2023-12-02 01:47:21 25 4
gpt4 key购买 nike

我正在用 C++ 编写共享库,它需要在标准 Win32 应用程序和 Windows 应用商店应用程序中工作。

但是对于特定的代码,我需要知道 DLL 是否加载到 Windows 应用商店应用程序中,以便我可以以适当的方式创建临时文件。

我知道使用 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 等代码进行多项编译时检查,但有没有办法在运行时进行此检查?

最佳答案

如果您打算在 DLL 中使用 Win32 桌面 API,则无法在运行时进行检查。 WACK Windows 应用商店提交工具检查所有 EXE 和 DLL 的导出和导入,并且将无法使用不在 Windows 应用商店 API 分区中的任何 API。

你应该阅读这个article有关处理此类多目标问题的建议。

理想情况下,您会让大部分 DLL 代码“按原样”在 Windows 应用商店中工作,然后可以将相同的代码用于 Win32 桌面版本,但您可能还担心“低级别”版本的操作系统以及在某些情况下需要使用 _WIN32_WINNT 版本保护。例如,您不能为 Windows 应用商店使用 CreateFile,也不能在 Windows 7 上使用 CreateFile2。

 #if (_WIN32_WINNT >= 0x0602)
HANDLE hFile = CreateFile2( szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr );
#else
HANDLE hFile = CreateFile( szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr );
#endif
if ( !hFile )
{
return HRESULT_FROM_WIN32( GetLastError() );
}

或者您可以使用像 fopen_s 这样的 CRT 函数来抽象它。

可以看看DirectXTex , DirectXTK , 和 DirectXMesh作为代码示例,利用这些技术为 Windows 8.0 的 Windows 应用商店、Windows 8.1 的 Windows 应用商店、Windows Phone 8.0、Windows Phone 8.1 和 Xbox One 以及用于 Windows 8.x、Windows 7 和 Windows 的 Win32 桌面构建代码远景。

另请记住,Windows 应用商店应用程序具有严格的 CRT 要求。适用于 Windows 8.0 的 Windows 应用商店应用必须使用 VS 2012 CRT,适用于 Windows 8.1 的 Windows 应用商店应用必须使用 VS 2013 CRT。

Universal Windows Platform apps are similar to Windows Store, but have a few more APIs added back and some new alternatives for older Windows desktop functionality. You must use VS 2015 CRT, specifically the Universal CRT.

关于visual-c++ - native c++ dll 如何检测它何时在 Windows 应用商店应用程序中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24919851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com