[NOTE] Using WinRT API from VBA

Dan_W

Well-known Member
Joined
Jul 11, 2018
Messages
1,878
Office Version
  1. 365
Platform
  1. Windows
I set out below my research re: WinRT APIs. These are separate to the Win32 API set and allow access to greater windows functionality.

I first came across them from the PowerToys Image2Text OCR tool, which was then implemented by the AHK community here: Easy OCR - AutoHotkey Community

From the code, it appears that they use a few Win32 APIs, namely RoGetActivationFactory

The information gathered thus far was written in a VB6 context, and I have yet to work out how to implement it in VBA. I though that this thread could be a good way of exploring the topic:

First, from VBForums, Diletantte raises the topic here: Registration-free WinRT-VBForums

And this ostensibly has a solution? Problems getting a window capture with Bitblt and PrintWindow.-VBForums
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Fafalone confirmed the above, and helpfully set out the following invocation function on the (excellent) TwinBasic Discord server:

VBA Code:
Private Function GetActivateInstance(ByVal ClassName As String, _
                                     ByVal iid As String, _
                                     ByRef pInstance As Long) As Boolean
    Dim bolRet As Boolean
    bolRet = False
    Dim hString As Long
    If WindowsCreateString(StrPtr(ClassName), Len(ClassName), hString) = S_OK Then
        If hString <> 0& Then
            Dim pIInspectable As Long
            If RoActivateInstance(hString, pIInspectable) = S_OK Then
                If pIInspectable <> 0& Then
                    If Invoke(pIInspectable, IUnknown_QueryInterface, _
                              VarPtr(Str2Guid(iid)), VarPtr(pInstance)) = S_OK Then
                        If pInstance <> 0& Then bolRet = True
                    End If
                    Call Release(pIInspectable)
                End If
            End If
            Call WindowsDeleteString(hString)
        End If
    End If
    GetActivateInstance = bolRet
End Function
 
Upvote 0
Fafalone directed me to a number of projects written by Franky over at ActiveVB.de - the relevant projects are prefaced with VBC_UWP.


I haven't had a chance to go through it all, and I'm still trying to wrap my head around COM interfaces, but I thought some of the more experienced and advanced members of the forums might have some insight/thoughts on the above.
 
Upvote 0
Mods - you should've just deleted the thread. Thank you.
 
Upvote 0

Forum statistics

Threads
1,215,068
Messages
6,122,950
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top