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
Using com-rs on Windows 7 (CoIncrementMTAUsage) #146
Comments
I'll let @kennykerr comment on this as he's the COM expert. I believe we would like to support Windows 7 since WinRT-rs also supports it even though the operating system is officially no longer supported by Microsoft. |
Yes, the You should be able to simply declare the In the long run, we will probably drop support for Windows 7 in both C++/WinRT and Rust/WinRT as Windows 7 is no longer supported. The only reason it's still maintained is for Chromium support, but I believe that support is also coming to an end soon. |
Thanks to you both for the guidance. I've come up with a solution that appears to work:
I'd love to get some confirmation that it is sound in principle, if that's possible - here's the full code. I had one tangentially related question: I see that I'm asking because I'm exposing a edit: Forgot to say that @kennykerr was indeed correct, and that "not calling init_runtime" is enough to not make the resulting executable import edit 2: just updated the link to |
Sorry for the delay, I didn't get a notification about this thread for some reason. Bumping another atomic ref count whenever a COM interface is created/copied can be costly. That may or not matter but in general that would be prohibitive. The other problem is that you don't necessarily know how many outstanding references there are. One COM object may well spin up other resources that rely on the apartment being alive but those won't necessarily be reflected in your Ideally, you can simply use Regarding Briefly, if you have a COM interface pointer on an MTA thread, you can freely move/copy that interface pointer to any other MTA thread. That's guaranteed to be safe. It's only when you cross apartment boundaries that you need to be careful. Oh, and here's how we handle https://github.com/microsoft/winrt-rs/blob/master/src/runtime.rs Of course, on Windows 7 we just assume that somebody else will take care of creating an apartment if necessary. Here's where we create an apartment on demand: Happy to answer any other questions you may have. And one more thing: many "COM" APIs don't actually need an apartment, so you might want to just check whether you even need any of this. |
How do you check this? Is that spelled out in documentation in some way? |
The docs might help. Generally, if a COM object is retrieved from an API-specific DLL export like |
I recently discovered CoIncrementMTAUsage is only available on Windows 8.0 and up itchio/itch#2454
I don't mind finding another solution on my own but my worry is that even then, any application that uses com-rs simply won't load on WIndows 7 because of the missing symbol.
Which means I'd have to maintain a fork that does not rely on CoIncrementMTAUsage - so I was just wondering if it could be behind a cargo feature, perhaps part of the default feature set?
I'm going to test my theory that CoIncrementMTAUsage indeed does not exist on Windows 7 and that a com-rs program as-is will never build with it, I'll update this issue with my findings, but I'd love to hear about someone who knows a lot more about COM than me on this.
The text was updated successfully, but these errors were encountered: