DirectX and COM interoperability for .NET #705
Replies: 3 comments 19 replies
-
Also, I expect HRESULT as a return type for many of these DirectX functions and COM methods but many of them seem to be changed to void. I made EnumAdapters fail and it threw an exception, which made me feel a little better about it. Is that the ideal way to handle that just use the try/catch mechanism instead of capturing HRESULTS like in C++ and checking return codes? |
Beta Was this translation helpful? Give feedback.
-
I'm gratified that you're pleased with CsWin32 so far.
The ".NET way" is like this:
That's another .NET convention. Learn more about PreserveSig. CsWin32 will default to using PreserveSig (which preserves the HRESULT return type) only for those members that the metadata describes as needing it. In the metadata, we annotate PreserveSig on methods that return non-S_OK success return codes (e.g. S_FALSE), which are otherwise impossible to detect in .NET. We also annotate APIs that commonly fail (e.g. when reaching the end of an enumeration). That leaves the exception-throwing behavior to those methods that one would not typically expect to fail. "comInterop": {
"preserveSigMethods": [
"IEnumString",
"ISpellChecker"
]
}
There isn't anything there that your program couldn't obtain after detecting a failing HRESULT, but yes, it's nice when it comes for free.
Well, I love to hear that! Please pick an issue and dig in. You might start with the help wanted issues, but you don't have to restrict yourself to that issue label. I recommend of anything more than a trivial change, comment on the issue that you'd like to take it, and how you intend to resolve it (e.g. describe the design or changes you'll make) and wait for my confirmation before proceeding to reduce risk of wasted effort if someone else is already working on it or the approach isn't the way we'll want to accept a PR for it later. I'm looking forward to hearing more from you! |
Beta Was this translation helpful? Give feedback.
-
So, I found my way here after a lot of research, landing on the WinMD repo and being directed to @AArnott by Mr. Kerr. I've managed to get CsWin32 to work for me for a simple test of DXGI and enumerating my adapters and outputs. This is lovely! I support this effort/project to the fullest because the possibilities here are truly amazing. It was like a Hollywood villain moment when I saw all those Win32 and COM APIs in C# IntelliSense! The power! 😄
So I would like to know, first of all: What can I do to help, support and contribute to this? I think bringing full DirectX to .NET is an important and noble effort, and this project is a godsend for that sort of thing. I'm more than happy to convert existing DirectX sample code over to C# with this, for example, that shouldn't be super hard. I can also possibly contribute to the code generation system as well as supplying feedback and testing things. Basically, whatever needs doing I'm willing to take a shot at it. Really interested in learning more about this and doing whatever I can to help things along and make improvements.
I'm sure to have a ton of questions. One I've got now is what is the most elegant way to get the RRID / GUID / UUID or whatever name you prefer of these COM interfaces. I couldn't figure out an obvious way other than clicking on Go to Definition and copying the Guid attribute string and using Guid.Parse. Ideally, this is something I think could be handled in a cleaner and more ".NET-like" way like a generic/Type argument (like with a where T: constraint) and it would infer the GUID from the attribute. Barring that, what would be a nice way to get it in my own code? Should I use reflection at startup to find them all or something? Don't really care for that idea but it would work. 🤷
Anyhow, I can't wait to have some fun with this converting some C++ samples to C# and building a game/3D framework and would love to assist! ❤️
Beta Was this translation helpful? Give feedback.
All reactions