Hi @Vancsisin László ,
Thanks for the detailed question. Based on the available Microsoft documentation, the following information may help clarify the behavior of IPortableDeviceManager::GetDevices.
The IPortableDeviceManager::GetDevices documentation does not explicitly describe its behavior after a failing HRESULT. The general COM Memory Management Rules provide the closest documented guidance.
Regarding E_POINTER, the documentation states that at least one required argument is NULL. Since the count-only call allows a NULL array when *pcPnPDeviceIDs = 0, a NULL pcPnPDeviceIDs is a clearly documented invalid argument. Other conditions and their effects on output storage are not explicitly documented.
For the output count and array entries, *pcPnPDeviceIDs is defined as the number of entries written, but its value after a failure is not specified. According to the COM Memory Management Rules, an in/out parameter should remain unchanged or be set to a value requiring no cleanup when a call fails. Therefore, neither the returned count nor the array entries should be treated as valid results after FAILED(hr).
Regarding ownership and cleanup, the API allocates each string on success, and the caller is responsible for freeing it using CoTaskMemFree. The recommended procedure is to zero-initialize the array before calling GetDevices. On S_OK or S_FALSE, the caller should free the returned strings based on the reported count. On FAILED(hr), the general COM rules indicate that no caller cleanup should be required, and the output count and array entries should not be relied upon. Scanning the original array capacity for non-NULL entries after a failure is not covered by a documented guarantee.
The general COM rules also require output pointers to be set to NULL on failure, including pointers within caller-allocated structures. Individual LPWSTR array entries are similar, but the documentation does not explicitly address this array scenario or identify any HRESULT-specific exceptions.
Overall, the public documentation does not provide GetDevices-specific guarantees about output values or ownership after a failing HRESULT. Since this forum primarily provides guidance based on publicly available documentation and does not have access to internal implementation details or engineering-level diagnostics, these behaviors cannot be authoritatively confirmed here. For further clarification and confirmation of the supported contract, contacting Windows Developer Support is recommended, as they can help route the question to the appropriate engineering team.
I hope this helps clarifying your requirements and answering your questions. If you find my response helpful, I would greatly appreciate it if you could follow the guide here so others experiencing similar behavior can benefit from it as well.