Closed jnm2 closed 1 year ago
I'm afraid this is unlikely to be 'fixed' because types like CREDENTIALW
are not mere handles. SafeHandle can only represent an IntPtr
. Even if we derived from it to add more fields, as a class it couldn't stand in for the CREDENTIALW
struct where methods took pointers to it.
I could see it working to have a CREDENTIALW* Pointer
property on the generated SafeHandle class, but I do see how this could be worse for discoverability. It would technically pass the all hurdles you mentioned though, since you can do anything with it that you can do with the current out CREDENTIAL*
pointer you get.
If you wanted to make things safer, the friendly overloads could take the safe handle instead of in CREDENTIALW
/ref CREDENTIALW
/CREDENTIALW*
parameters. The friendly overload would do DangerousAddRef etc and pass safeHandle.Pointer
to the p/invoke method.
Thanks for describing more about what you were thinking. But I don't think we're going to go with that. If we find many more types that could fit the same pattern it might be worth it, but as a one-off case, this is too much customization to be worthwhile IMO.
Right now, we're forced to write
try
...finally
around a pointer.This applies to these functions and possibly more: