RegDeleteKey 和 RegDeleteKeyEx [英] RegDeleteKey and RegDeleteKeyEx

查看:22
本文介绍了RegDeleteKey 和 RegDeleteKeyEx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,它将使用 API RegDeleteKeyRegDeleteKeyEx 递归删除一些注册表项.困扰我的是 RegDeleteKeyEx 不是为低于 XP x64 Professional 定义的,所以现在这个限制限制了我的应用程序.有什么方法可以让我同时使用这两个 API 并兼容从 XP x86 到 Win7 x64 吗?

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 ?

推荐答案

为了让您的应用程序在不存在 RegDeleteKeyEx 的旧系统中运行,您需要避免静态链接到此 API.也就是说,您不直接使用此函数,而是在运行时通过 GetProcAddress 获取其指针.如果成功,则 API 可用,您可以使用它(或者您可以检查操作系统版本).

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).

看看这里:如何我可以使用 RegDeleteKeyEx 吗:

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

RegDeleteKey 可以直接使用,因为它存在于所有目标平台.

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

这篇关于RegDeleteKey 和 RegDeleteKeyEx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆