RegDeleteKey and RegDeleteKeyEx

不羁的心 提交于 2019-12-24 04:02:47

问题


I am writing an app which will remove some Registry keys recursively using API RegDeleteKey or RegDeleteKeyEx. What is bothering me is that RegDeleteKeyEx is not defined for less than XP x64 Professional, so now this limitation is limiting my app. Is there any way in which I can use both APIs with compatibility from XP x86 to Win7 x64 ?


回答1:


In order for your app to run in old systems where RegDeleteKeyEx does not exist, you need to avoid static linking to this API. That is, you don't use this function directly, adn instead you obtain its pointer on runtime via GetProcAddress. If it succeeds, then the API is available and you can use it (alternatively you can check OS version).

Have a look here: How can I use RegDeleteKeyEx:

   hAdvAPI32 = LoadLibrary(_T("AdvAPI32.dll"));
   ASSERT(hAdvAPI32 != NULL);
   _RegDeleteKeyEx = (PFN_RegDeleteKeyEx)GetProcAddress(hAdvAPI32 , "RegDeleteKeyEx");
   ASSERT(_RegDeleteKeyEx != NULL);

RegDeleteKey can be used directly since it exists in all target platforms.



来源:https://stackoverflow.com/questions/12797905/regdeletekey-and-regdeletekeyex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!