winapi – 如何从使用“Project Centennial converter”转换为UW
发布时间:2020-12-13 20:43:30 所属栏目:Windows 来源:网络整理
导读:我有一个在VS 2008中开发的本机C / MFC应用程序,没有.NET的东西,我使用 Project Centennial converter转换为UWP应用程序.所以现在我有一个.appx包在Windows 10 v 1607中作为UWP应用程序运行. 我的下一个目标是在提交到Windows应用商店之前添加应用内购买支持
我有一个在VS 2008中开发的本机C / MFC应用程序,没有.NET的东西,我使用
Project Centennial converter转换为UWP应用程序.所以现在我有一个.appx包在Windows 10 v 1607中作为UWP应用程序运行.
我的下一个目标是在提交到Windows应用商店之前添加应用内购买支持. 问题是如何从本机C或C代码从纯Win32应用程序访问Windows.Services.Store命名空间?
使用WRL.以下是有关如何购买应用内购买的示例:
#include <windows.h> #include <Windows.Services.Store.h> #include <wrl.h> using namespace ABI::Windows::Foundation; using namespace ABI::Windows::Services::Store; using namespace Microsoft::WRL; using namespace Microsoft::WRL::Wrappers; #define CheckHr(hr) do { if (FAILED(hr)) __debugbreak(); } while (false) const wchar_t kItemFriendlyName[] = L"10 coins"; const wchar_t kItemStoreId[] = L"ten_coins"; void OnPurchaSEOperationDone(IAsyncOperation<StorePurchaseResult*>* operation,AsyncStatus status); void Purchase10Coins() { ComPtr<IStoreContextStatics> storeContextStatics; auto hr = RoGetActivationFactory(HStringReference(L"Windows.Services.Store.StoreContext").Get(),__uuidof(storeContextStatics),&storeContextStatics); CheckHr(hr); ComPtr<IStoreContext> storeContext; hr = storeContextStatics->GetDefault(&storeContext); CheckHr(hr); ComPtr<IStorePurchasePropertiesFactory> purchasePropertiesFactory; hr = RoGetActivationFactory(HStringReference(L"Windows.Services.Store.StorePurchaseProperties").Get(),__uuidof(purchasePropertiesFactory),&purchasePropertiesFactory); CheckHr(hr); ComPtr<IStorePurchaseProperties> purchaseProperties; hr = purchasePropertiesFactory->Create(HStringReference(kItemFriendlyName).Get(),&purchaseProperties); CheckHr(hr); ComPtr<IAsyncOperation<StorePurchaseResult*>> purchaSEOperation; hr = storeContext->RequestPurchaseWithPurchasePropertiesAsync(HStringReference(kItemStoreId).Get(),purchaseProperties.Get(),&purchaSEOperation); CheckHr(hr); // Change the following line to call Callback<IAsyncOperationCompletedHandler<StorePurchaseResult*>> if you want the callback to happen back on the UI thread // Implementing FtmBase allows it to fire on the thread the operation finished auto onCompletedCallback = Callback<Implements<RuntimeClassFlags<ClassicCom>,IAsyncOperationCompletedHandler<StorePurchaseResult*>,FtmBase>>( [](IAsyncOperation<StorePurchaseResult*>* operation,AsyncStatus status) { OnPurchaSEOperationDone(operation,status); return S_OK; }); hr = purchaSEOperation->put_Completed(onCompletedCallback.Get()); CheckHr(hr); } void OnPurchaSEOperationDone(IAsyncOperation<StorePurchaseResult*>* operation,AsyncStatus status) { if (status != AsyncStatus::Completed) { // It failed for some reason. Find out why. ComPtr<IAsyncInfo> asyncInfo; auto hr = operation->QueryInterface(__uuidof(asyncInfo),&asyncInfo); CheckHr(hr); HRESULT errorCode; hr = asyncInfo->get_ErrorCode(&errorCode); CheckHr(hr); // Do something with the errorCode // Return once error is handled return; } ComPtr<IStorePurchaseResult> purchaseResult; auto hr = operation->GetResults(&purchaseResult); CheckHr(hr); StorePurchaseStatus purchaseStatus; hr = purchaseResult->get_Status(&purchaseStatus); CheckHr(hr); switch (purchaseStatus) { case StorePurchaseStatus_Succeeded: case StorePurchaseStatus_AlreadyPurchased: // Success. Product was purchased break; case StorePurchaseStatus_NotPurchased: // User canceled the purchase break; case StorePurchaseStatus_NetworkError: // The device could not reach windows store break; case StorePurchaseStatus_ServerError: // Something broke on the server break; } } 以下是检查应用程序是否正在试用的方法: void CheckIsTrial(std::function<void(bool)> onCompleted) { ComPtr<IStoreContextStatics> storeContextStatics; auto hr = RoGetActivationFactory(HStringReference(L"Windows.Services.Store.StoreContext").Get(),&storeContextStatics); CheckHr(hr); ComPtr<IStoreContext> storeContext; hr = storeContextStatics->GetDefault(&storeContext); CheckHr(hr); ComPtr<IAsyncOperation<StoreAppLicense*>> getLicenSEOperation; hr = storeContext->GetAppLicenseAsync(&getLicenSEOperation); CheckHr(hr); hr = getLicenSEOperation->put_Completed(Callback<Implements<RuntimeClassFlags<ClassicCom>,IAsyncOperationCompletedHandler<StoreAppLicense*>,FtmBase>>( [onCompleted{ std::move(onCompleted) }](IAsyncOperation<StoreAppLicense*>* operation,AsyncStatus status) { if (status != AsyncStatus::Completed) { // It failed for some reason. Find out why. ComPtr<IAsyncInfo> asyncInfo; auto hr = operation->QueryInterface(__uuidof(asyncInfo),&asyncInfo); CheckHr(hr); HRESULT errorCode; hr = asyncInfo->get_ErrorCode(&errorCode); CheckHr(hr); // Do something with the errorCode // Return once error is handled return S_OK; } ComPtr<IStoreAppLicense> appLicense; auto hr = operation->GetResults(&appLicense); CheckHr(hr); boolean isActive,isTrial = false; hr = appLicense->get_IsActive(&isActive); CheckHr(hr); if (isActive) { hr = appLicense->get_IsTrial(&isTrial); CheckHr(hr); } onCompleted(static_cast<bool>(isActive)); return S_OK; }).Get()); CheckHr(hr); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- php在windows环境下获得cpu内存实时使用率(推荐)
- .net – Windows.System.Threading.ThreadPool和System.Thr
- windows-server-2003 – 仅在Windows Server 2003上启用控制
- Windows 7 – Windows 7:防止应用程序失去焦点
- windows下IOS证书制作
- windows – Webstorm 11中的菜单和工具栏字体大小
- 在Windows 7的Git Bash中,运行黄瓜或rspec时,颜色显示为代码
- 如何在win7 x64上使用带有php(xampp)的oracle客户端11.2
- windows-server-2012-r2 – 如何为Windows Server功能指定备
- wix – 执行安装后需要提升的自定义操作
推荐文章
站长推荐
热点阅读