Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document whether it's possible to write an out-of-process WinRT component in C# #526

Closed
rigdern opened this issue Nov 13, 2016 · 4 comments

Comments

@rigdern
Copy link

rigdern commented Nov 13, 2016

This is in reference to the out-of-process WinRT component sample.

Is it possible to write an out-of-process WinRT component in C#? If it is, some code should probably be added to the sample. If not, this fact should probably be noted in the sample's README.

Also, if there is some documentation on MSDN about writing out-of-process WinRT components, it would be nice if the sample's README linked to it.

Here's a scenario to help frame this issue. Imagine being a developer who has only written Windows Store Apps in C#. Coming across this sample would raise some questions:

I can write WinRT components in C#, can I write out-of-process WinRT components in C#? If not, why not? How is an out-of-process WinRT component different than a normal one? If I know how to write a WinRT component, where can I go to learn about the concepts needed to write an out-of-process one?

Adam Comella
Mircosoft Corp.

@softworkz
Copy link

I would like to know this as well..

@oldnewthing
Copy link
Member

I've asked the feature team to respond.

@BenJKuhn
Copy link
Member

To the best of my knowledge, this is not possible to do directly in in C#. It's likely also not possible in C++ /CX. The issue is that you need to implement an executable that calls CoreApplication.RunWithActivationFactories in start-up. I don't believe the activation factories for C# types are readily exposed to the code within the module.

You could probably achieve the equivalent result by building an in-proc winrt component DLL in C#, and then, based on the sample here, build a wrapper .exe that exposes types from the C# DLL by implementing the required IGetActivationFactory interface and calling DllGetActivationFactory method implemented on the C# DLL. Use LoadPackagedLibrary to load the C# DLL containing the component. You'll need to hand-edit your appx registration to list the components as out-of-proc, rather than in-proc. I haven't tried this. It's a moderate amount of work to put together and you might hit a snag that I haven't considered, but I don't know of a reason why it wouldn't work.

Note that if you need to target Win8, you may need to provide COM proxies as well. To do that, you can use the WinMDIdl tool from the SDK to generate IDL from your C# types. Compile the IDL to create proxies, and add the registration to the manifest. For Win10, metadata-based marshalling implemented in the OS should take care of this for you.

Ben

@oldnewthing
Copy link
Member

I'll add a note to the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants