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

Fix NullReferenceException in friendly overloads of COM methods with optional pointer parameters #1109

Merged
merged 5 commits into from
Jan 10, 2024

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented Jan 10, 2024

Optional parameters cannot be expressed with the ref modifier on COM methods in order to avoid a pointer type. Doing so disallows the possibility of passing in null. Even Unsafe.NullRef<T>() does not work because the .NET interop layer throws NullReferenceException when that's done.

Instead, we leave it as a pointer type.

An alternative to this may be to declare the parameter as an array that allows null or exactly 1 element. But the API wouldn't describe itself very well, and enforcement wouldn't exist, leading to possible runtime failures.

Fixes #1081


AI generated summary

This pull request includes a significant number of changes to various files in the codebase. The most important changes include adding a new enum to categorize different elements being generated in Generator.cs, modifying methods in Generator.Com.cs to generate appropriate type syntax based on the generating element, and adding a new test method in COMTests.cs to verify the declaration of COM methods.

Main interface changes:

Other important changes:

Please note that due to the large number of changes and limited space, only a subset of the changes are listed here.

@AArnott AArnott merged commit efd80a7 into main Jan 10, 2024
2 checks passed
@AArnott AArnott deleted the fix1081 branch January 10, 2024 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calling IMMDevice.Activate() results in a NullReferenceException
1 participant