问题
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