While answering this question, I have come across quite a few similar questions (though it took a lot of digging):
- How to pass a nullable type to a P/invoked function
- P/invoke function taking pointer to struct
- How to handle optional struct parameters when calling C functions from C#
- Calling Win API in C# with P/Invoke when _Out_ parameters can be NULL or non-NULL
- C# interop passing multiple nullable parameters
- How to P/Invoke SetFileTime with null parameters?
- How do I assign a null value to a struct for a pinvoke call?
- C#: How to pass null to a function expecting a ref?
The last link is probably the best duplicate candidate, but it lacks answers that are included in other posts. It also feels like these questions are all a little too specific to be used as canonical questions. Some address optional parameters specifically, while others just want to know how to pass null.
My questions is then, which of these should I be using as the canonical question? Should I just create a new canonical question and post an answer that encompasses all the answers on these posts, or should I just post such an answer to one of these questions?
Update
I went ahead and created a canonical post for this, with an answer that includes all the different solutions I could find. I'd be happy to delete/change it if that's the consensus that is reached.
Feel free to comment/add other solutions if you know of additional methods. (A CW answer with all the options is also a possibility, that's open for discussion).