开发者

If RegOpenKeyEx Does Not Return ERROR_SUCCESS Am I Guaranteed that the HKEY Was Not Opened?

开发者 https://www.devze.com 2023-04-10 17:43 出处:网络
Reading Microsoft\'s documentation on RegOpenKeyEx and RegCloseKey I am unsure of whether or not I need to call the close function if RegOpe开发者_JAVA百科nKeyEx fails.

Reading Microsoft's documentation on RegOpenKeyEx and RegCloseKey I am unsure of whether or not I need to call the close function if RegOpe开发者_JAVA百科nKeyEx fails.

Please point me to a definitive source indicating if I need to always call RegCloseKey or if it only needs to be called when RegOpenKeyEx returns ERROR_SUCCESS.

References:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724897%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724837%28v=vs.85%29.aspx


RegOpenKeyEx will only return a valid key handle if ERROR_SUCCESS is the returned value. This is where the caller is responsible for closing the key, otherwise no closing required and key is not opened. This is the the assumed agreement regarding responsibility to close the opened handle, though not explicitly mentioned in RegOpenKeyEx function documentation.

This is also consistent across API samples. If you are unsure after checking sample code in the MSDN article, here is another one: http://msdn.microsoft.com/en-us/library/aa384182%28VS.85%29.aspx


I think if you look at the example listed under your reference links you can see that it does not call RegCloseKey if lResult does not return ERROR_SUCCESS

This is the link to it:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724235(v=vs.85).aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号