Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic calls to WinRT interfaces

I'd like to make dynamic (i.e. reflection-based) calls to WinRT objects, from C or C++. I will assume that I have winmd files available at run-time, so that I can find out what the methods are and what parameters they take.

In OLE Automation, IDispatch was then available to make the actual calls. However, WinRT objects don't support IDispatch. How can I then make calls? Do I need some kind of FFI library that will allow to dynamically pass the parameters, according to the COM calling convention of the processor? Or do I really need "static" class/struct declarations (for C/C++)?

Edit: The target system is a metro-style app. That precludes solutions involving banned APIs.

like image 490
Martin v. Löwis Avatar asked May 05 '12 07:05

Martin v. Löwis


1 Answers

It is certainly possible to build what you're describing - under the covers that's exactly what the Chakra Javascript engine does with winrt metadata and is similar to what the CLR does. Both of these language projections discover the APIs at runtime and build up the low level assembly to make this happen.

It's a lot of work and isn't particularly pleasant but it's absolutely technically possible. The windows metadata contains all the information needed to create stubs for the APIs and structures.

like image 193
ReinstateMonica Larry Osterman Avatar answered Oct 03 '22 11:10

ReinstateMonica Larry Osterman