wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了winapi – 如何从使用“Project Centennial converter”转换为UWP的Win32应用程序访问Windows.Services.Store命名空间以启用应用内购买?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我有一个在VS 2008中开发的本机C / MFC应用程序,没有.NET的东西,我使用 Project Centennial converter转换为UWP应用程序.所以现在我有一个.appx包在Windows 10 v 1607中作为UWP应用程序运行. 我的下一个目标是在提交到Windows应用商店之前添加应用内购买支持. 问题是如何从本机C或C代码从纯Win32应用程序访问Windows.S
我有一个在VS 2008中开发的本机C / MFC应用程序,没有.NET的东西,我使用 Project Centennial converter转换为UWP应用程序.所以现在我有一个.appx包在Windows 10 v 1607中作为UWP应用程序运行.

我的下一个目标是在提交到Windows应用商店之前添加应用内购买支持.

问题是如何从本机C或C代码从纯Win32应用程序访问Windows.Services.Store命名空间?

使用WRl.以下是有关如何购买应用内购买的示例: @H_618_23@#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 OnPurcha@L_674_11@perationDone(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*>> purcha@L_674_11@peration; hr = storeContext->requestPurchaseWithPurchasePropertiesAsync(HStringReference(kItemStorEID).Get(),purchaseProperties.Get(),&purcha@L_674_11@peration); 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) { OnPurcha@L_674_11@perationDone(operation,status); return S_OK; }); hr = purcha@L_674_11@peration->put_Completed(onCompletedCallBACk.Get()); checkHr(hr); } void OnPurcha@L_674_11@perationDone(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; } }

以下是检查应用程序是否正在试用的方法

@H_618_23@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*>> getLicen@L_674_11@peration; hr = storeContext->GetAppLicenseAsync(&getLicen@L_674_11@peration); checkHr(hr); hr = getLicen@L_674_11@peration->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); }

大佬总结

以上是大佬教程为你收集整理的winapi – 如何从使用“Project Centennial converter”转换为UWP的Win32应用程序访问Windows.Services.Store命名空间以启用应用内购买?全部内容,希望文章能够帮你解决winapi – 如何从使用“Project Centennial converter”转换为UWP的Win32应用程序访问Windows.Services.Store命名空间以启用应用内购买?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。