.NET Framework Interop (CLR, C#, VB)

Post your working scripts, libraries and tools for AHK v1.1 and older
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: .NET Framework Interop (CLR, C#, VB)

Post by robodesign » 03 Mar 2023, 14:07

Hello!

I am trying to use this library to open a Windows Store add-on purchase. But I do not know how to properly invoke the C# code from here:

https://learn.microsoft.com/en-us/windows/uwp/monetize/enable-subscription-add-ons-for-your-app
and
https://learn.microsoft.com/fr-fr/windows/uwp/monetize/in-app-purchases-and-trials#desktop

Code: Select all

using Windows.Services.Store
using System.Threading.Tasks 

public async void PurchaseAddOn(string storeId)
{
    if (context == null)
    {
        context = StoreContext.GetDefault();

        // Obtain window handle by passing in pointer to the window object
        var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(windowObject);
        // Initialize the dialog using wrapper funcion for IInitializeWithWindow
        WinRT.Interop.InitializeWithWindow.Initialize(context, hwnd);

        // If your app is a desktop app that uses the Desktop Bridge, you
        // may need additional code to configure the StoreContext object.
        // For more info, see https://aka.ms/storecontext-for-desktop.
    }

    workingProgressRing.IsActive = true;
    StorePurchaseResult result = await context.RequestPurchaseAsync(storeId);
    workingProgressRing.IsActive = false;

    // Capture the error message for the operation, if any.
    string extendedError = string.Empty;
    if (result.ExtendedError != null)
    {
        extendedError = result.ExtendedError.Message;
    }

    switch (result.Status)
    {
        case StorePurchaseStatus.AlreadyPurchased:
            textBlock.Text = "The user has already purchased the product.";
            break;

        case StorePurchaseStatus.Succeeded:
            textBlock.Text = "The purchase was successful.";
            break;

        case StorePurchaseStatus.NotPurchased:
            textBlock.Text = "The purchase did not complete. " +
                "The user may have cancelled the purchase. ExtendedError: " + extendedError;
            break;

        case StorePurchaseStatus.NetworkError:
            textBlock.Text = "The purchase was unsuccessful due to a network error. " +
                "ExtendedError: " + extendedError;
            break;

        case StorePurchaseStatus.ServerError:
            textBlock.Text = "The purchase was unsuccessful due to a server error. " +
                "ExtendedError: " + extendedError;
            break;

        default:
            textBlock.Text = "The purchase was unsuccessful due to an unknown error. " +
                "ExtendedError: " + extendedError;
            break;
    }

    return textBlock;
}
the AHK part:

Code: Select all

#include CLR.ahk
CLR_Start()
FileRead c#, code.cs

asm := CLR_CompileC#(c#, "System.dll | Windows.Services.Store | System.Threading.Tasks | WinRT")
obj := CLR_CreateObject(asm, "Foo")
winStoreID := "9NQRH8V7RF9NLIFE"
r := obj.PurchaseAddOn(winStoreID)
msgbox, %r%
return r

I get the following error: missing header files for Windows.Services.Store , WinRT and System.Threading.Tasks.

Thank you.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

User avatar
xMaxrayx
Posts: 168
Joined: 06 Dec 2022, 02:56
Contact:

Re: .NET Framework Interop (CLR, C#, VB)

Post by xMaxrayx » 16 Apr 2024, 11:37

sorry Im lost here how to use compiled DLL?

  • * c# source

    Code: Select all

    namespace consoleDLLtest_v2
    {
        public class ClassHello_v2
        {
    
    
            public string Hi()
            {
                return "Hi, this is from DLL";
            }
        }
    }
    
    
    * Filename :
    "ClassLibrary2.dll"


    * Net framework version:
    about 4.5
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Post Reply

Return to “Scripts and Functions (v1)”