dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.81k stars 196 forks source link

SearchApi.IQuerySolution.Resolve() should not require unsafe pointer for parameter "SYSTEMTIME* pstReferenceTime" #451

Closed zhuxb711 closed 7 months ago

zhuxb711 commented 8 months ago

Describe the bug and how to reproduce Vanara should not allow passing the unsafe pointer as the parameter to the "SearchApi.IQuerySolution.Resolve()", which will force every program to enable unsafe switch. Also unsafe code will break the IAsynEnumerable pattern.

image image

Expected behavior Should be the same as 3.4.17

dahall commented 8 months ago

The parameter notes for pstReferenceTime indicate

A pointer to a SYSTEMTIME value to use as the reference date and time. A null pointer can be passed if sqro is set to SQRO_DONT_RESOLVE_DATETIME. The 3.4.17 version couldn't allow for that so that prompted the change.

Can you help me understand more about your comment "Also unsafe code will break the IAsynEnumerable pattern."? Do you mean that you have to then have unsafe blocks? If that is the case, I can overloads that support both options in Vanara so you can just use safe code.

zhuxb711 commented 8 months ago

Yes, better provide a overload for that because it's not possible to create a variable (unsafe pointer) without enabling unsafe switch for C#. For the code in 4.0.0, it's no possible to use fully safe pointer if you defined something parameter instead of IntPtr

zhuxb711 commented 8 months ago

The parameter notes for pstReferenceTime indicate

A pointer to a SYSTEMTIME value to use as the reference date and time. A null pointer can be passed if sqro is set to SQRO_DONT_RESOLVE_DATETIME.

The 3.4.17 version couldn't allow for that so that prompted the change.

Can you help me understand more about your comment "Also unsafe code will break the IAsynEnumerable pattern."? Do you mean that you have to then have unsafe blocks? If that is the case, I can overloads that support both options in Vanara so you can just use safe code.

If you try to use unsafe code in a function that returns IAsyncEnumerable. You will get an error from the compiler: "Unsafe code may not appear in iterators"

zhuxb711 commented 8 months ago

FYR: C# Compiler Error CS1629

dahall commented 8 months ago

Thank you. I'll dig into this and find a resolution.

dahall commented 7 months ago

Fixed in 4.0.1

zhuxb711 commented 7 months ago

Thanks, and hope will release 4.0.1 soon~