读取注册表的内容----急

me2love 2004-08-11 11:26:50
我的代码是:
char *data = new char[100+1];

LPDWORD size = new DWORD;
*size = 100;
result = ::RegQueryValueEx(hKey,
"IFDType",
NULL,
REG_SZ,
(LPBYTE *)data,
&size);
它的错误信息为:

error C2664: 'RegQueryValueExA' : cannot convert parameter 4 from 'const int' to 'unsigned long *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
...全文
166 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
DoubleJiang 2004-08-11
  • 打赏
  • 举报
回复
RegQueryValueEx
The RegQueryValueEx function retrieves the type and data for a specified value name associated with an open registry key.

LONG RegQueryValueEx(
HKEY hKey, // handle to key to query
LPTSTR lpValueName, // address of name of value to query
LPDWORD lpReserved, // reserved
LPDWORD lpType, // address of buffer for value type
LPBYTE lpData, // address of data buffer
LPDWORD lpcbData // address of data buffer size
);

Parameters
hKey
Handle to a currently open key or any of the following predefined reserved handle values:
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
Windows NT: HKEY_PERFORMANCE_DATA
Windows 95 and Windows 98: HKEY_DYN_DATA

lpValueName
Pointer to a null-terminated string containing the name of the value to query.
If lpValueName is NULL or an empty string, "", the function retrieves the type and data for the key's unnamed or default value, if any.

Windows 95 and Windows 98: Every key has a default value that initially does not contain data. On Windows 95, the default value type is always REG_SZ. On Windows 98, the type of a key's default value is initially REG_SZ, but RegSetValueEx can specify a default value with a different type.

Windows NT: Keys do not automatically have an unnamed or default value. Unnamed values can be of any type.

lpReserved
Reserved; must be NULL.
lpType
Pointer to a variable that receives the type of data associated with the specified value. The value returned through this parameter will be one of the following: Value Meaning
REG_BINARY Binary data in any form.
REG_DWORD A 32-bit number.
REG_DWORD_LITTLE_ENDIAN A 32-bit number in little-endian format. This is equivalent to REG_DWORD.
In little-endian format, a multi-byte value is stored in memory from the lowest byte (the "little end") to the highest byte. For example, the value 0x12345678 is stored as (0x78 0x56 0x34 0x12) in little-endian format.

Windows NT, Windows 95, and Windows 98 are designed to run on little-endian computer architectures. A user may connect to computers that have big-endian architectures, such as some UNIX systems.

REG_DWORD_BIG_ENDIAN A 32-bit number in big-endian format.
In big-endian format, a multi-byte value is stored in memory from the highest byte (the "big end") to the lowest byte. For example, the value 0x12345678 is stored as (0x12 0x34 0x56 0x78) in big-endian format.

REG_EXPAND_SZ A null-terminated string that contains unexpanded references to environment variables (for example, "%PATH%"). It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions. To expand the environment variable references, use theExpandEnvironmentStrings function.
REG_LINK A Unicode symbolic link.
REG_MULTI_SZ An array of null-terminated strings, terminated by two null characters.
REG_NONE No defined value type.
REG_RESOURCE_LIST A device-driver resource list.
REG_SZ A null-terminated string. It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions.


The lpType parameter can be NULL if the type is not required.

lpData
Pointer to a buffer that receives the value's data. This parameter can be NULL if the data is not required.
lpcbData
Pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the lpData parameter. When the function returns, this variable contains the size of the data copied to lpData.
If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, then lpcbData will also include the size of the terminating null character.

The lpcbData parameter can be NULL only if lpData is NULL.

If the buffer specified by lpData parameter is not large enough to hold the data, the function returns the value ERROR_MORE_DATA, and stores the required buffer size, in bytes, into the variable pointed to by lpcbData.

If lpData is NULL, and lpcbData is non-NULL, the function returns ERROR_SUCCESS, and stores the size of the data, in bytes, in the variable pointed to by lpcbData. This lets an application determine the best way to allocate a buffer for the value's data.

Window NT: If hKey specifies HKEY_PERFORMANCE_DATA and the lpData buffer is too small, RegQueryValueEx returns ERROR_MORE_DATA but lpcbData does not return the required buffer size. This is because the size of the performance data can change from one call to the next. In this case, you must increase the buffer size and call RegQueryValueEx again passing the updated buffer size in the lpcbData parameter. Repeat this until the function succeeds. You need to maintain a separate variable to keep track of the buffer size, because the value returned by lpcbData is unpredictable.

Return Values
If the function succeeds, the return value is ERROR_SUCCESS.

If the function fails, the return value is a nonzero error code defined in WINERROR.H. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

Remarks
The key identified by hKey must have been opened with KEY_QUERY_VALUE access. To open the key, use the RegCreateKeyEx or RegOpenKeyEx function.

If the value data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, and the ANSI version of this function is used (either by explicitly calling RegQueryValueExA or by not defining UNICODE before including the WINDOWS.H file), this function converts the stored Unicode string to an ANSI string before copying it to the buffer pointed to by lpData.

Window NT: When calling the RegQueryValueEx function with hKey set to the HKEY_PERFORMANCE_DATA handle and a value string of a specified object, the returned data structure sometimes has unrequested objects. Don't be surprised; this is normal behavior. When calling the RegQueryValueEx function, you should always expect to walk the returned data structure to look for the requested object.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winreg.h.
Import Library: Use advapi32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
Registry Overview, Registry Functions,ExpandEnvironmentStrings, RegCreateKeyEx, RegEnumKey, RegEnumKeyEx, RegEnumValue, RegOpenKeyEx, RegQueryInfoKey, RegQueryValue


me2love 2004-08-11
  • 打赏
  • 举报
回复
谢谢您们的回复,但是还是不正确
bohut 2004-08-11
  • 打赏
  • 举报
回复
unsigned char *lpData = new unsigned char[100];
DWORD datasize;
result = ::RegQueryValueEx(hKey,
"IFDType",
NULL,
NULL,
lpData ,
&datasize);
无敌魔仙 2004-08-11
  • 打赏
  • 举报
回复
错误为类型不符,要求是'unsigned long *',但你提供的是 'const int'
快乐鹦鹉 2004-08-11
  • 打赏
  • 举报
回复
REG_SZ regSz;
result = ::RegQueryValueEx(hKey,
"IFDType",
NULL,
®Sz,
(LPBYTE *)data,
&size);
这样呢?
快乐鹦鹉 2004-08-11
  • 打赏
  • 举报
回复
result = ::RegQueryValueEx(hKey,
"IFDType",
NULL,
®_SZ,
(LPBYTE *)data,
&size);
这样呢?
Win8的封装 用:Sc Sc封装工具简介 Sysprep Chief Executive Officer 意为系统封装首席执行官,简称Sc,由系统总裁网站(http://www.sysceo.com/)开发研制,是一款面对Windows操作系统封装的一款辅助工具,界面友好、简单易用、智能高效、自定义强,是学习研究系统封装爱好者的首选。 我的效果图: WIN 8 的驱动可以直接用:万能驱动助理 万能驱动助理(从5.25版起),WIN 7的驱动完全运行WIN 8 直接不能用,可以做一点点的修改,就完全可以了 这是WIN 7的 这样WIN8就完全支持了 最新公测版本号为:Beta1.2.0.1009 支持平台: Windows XP/2000/2003/7/2008/8 关于封装WIN8卡住不执行问题的解决办法: 这个是权限问题!请检查系统用户是否为管理员,如果是,不要,再查看一下UCA是否打开,如果打开请关闭,如果已经关闭,请在检查一下注册表[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System] "FilterAdministratorToken"=dword:00000001,把这里值改成0,再者请右击程序管理员运行! 功能简要: 五大自定义功能模块:母盘系统、工具大全、目标系统、计划任务、部署过程、封装过程。 1、母盘系统:自动智能扫描并检测当前被封装的系统状态,全面扫描系统信息、封装部署必备文件、封装部署所依赖的各大细节、系统精简等多项导致封装部署失败的文件和事项,并且提供系统修复和精简功能。 2、工具大全:提供封装相关的精品辅助软件的下载,每款软件都经过多次测试无误的精品软件,一站式封装全套软件一网打尽,并提供及时更新和测试。 3、目标系统:对部署的目标系统的强大自定义设置模块,主要设置有:常规优化、智能转移目标系统资料、智能删除部署使用过驱动包、智能转换NTFS文件系统、预制随机计算机名、智能识别笔记本并做相应处理、设置固定IP和预制随机IP、设置目标系统用户名、安装序列号等等。 4、计划任务:对部署过程提供的强大自定义外部软件和设置的接口模块、接口数量无限,提供的接口过程有5个,分别是:系统部署前、部署中、部署后、首次进系统登录时,首次进系统进桌面时;提供运行的接口类型有4种,分别是:运行软件、导入注册表、删除文件、删除文件夹;对于运行的接口方式有4种,分别是:正常运行、隐藏运行、最大化运行、最小化运行;对于运行接口完成后还提供删除接口源文件的功能,并每个接口间运行都可以自定义等待时间、不等待、等待上一个接口运行完成的模式。 5、部署过程:对部署过程的一些自定义设置模块,主要设置有:部署背景图(单张、多张轮流播放)、部署前密码验证机制、部署前安装协议机制、部署前加载usb设备驱动、激活Administrator用户、自定义部署分辨率、自定义系统部署文件颜色、自定义部署模块。 6、封装过程:对系统封装过程的一些自定义设置模块,主要设置有:自动运行Sysprep.exe进行封装、自动卸载硬件驱动、自动更改处理硬件HAL、加载扩展SRS驱动、自动保存当前系统的输入法状态、封装后锁定计算机信息防止二次修改等等。 细节亮点: 1、Sc支持系统安装意外断电续装功能(支持VISTA以下系统)。 2、Sc部署中使用快捷键Ctrl+F9可以跳过安装过程直接进入系统(支持VISTA以下系统)。 3、Sc部署中将智能处理因网卡驱动卡在部署过程的功能,此功能支持任何第三方驱动包的使用(支持VISTA以下系统)。 4、Sc部署完成后智能转移IE收藏夹和我的文档能使系统立即生效,无需重启计算机。 5、Sc部署多元化部署模块,所有模块的细节均可自定义,如字体颜色,进度条底色,高亮颜色,坐标位置等等。 6、Sc提供完善的反馈机制,SC程序自带反馈功能,可以通过文字和图片的形式反馈给我们,在部署过程中如果发生意外,SC部署程序会自动在WINDOWS文件夹下生成一个Scbug.html文件,为了不遗留文件在客户机上,该文件会在第二次重启自动删除,所以当您在首次进桌面如果发现该文件,您可以提交给我们! 配置文件: 对Sc进行设置后都会在根目录下产生一个名为Scdata.dat配置文件,为了防止破坏配置文件,对配置文件进行了加密,该配置文件只能通过运行Sc软件进行修改,配置文件自动保存最后一次设置的状态。 更新日志: 最新版本:Beta1.2.0.1009 (2012年12月17日更新) ------------------------------------ 1.2.0.1009更新列表 1、更新调用外部接口兼容问题; 2、更新部署程序; 3、新增可选自动清理多余SRS驱动选项; 历史版本更新日志: ------------------------------------ 1.2.0.1006更新列表 1、修复精简模块里WIN7下删除帮助文件导致EXPLORER结束的BUG; 2、改进精简模块里WIN7下精简%windir%\winsxs\Backup假死现象; 3、更新部署模块对没有使用SC自带SRS驱动的清理工; 4、更新部署模块绚丽进度条模式皮肤; 5、更新精简模块的部分函数; 6、更新程序图标。 1.2.0.1003更新列表 1、修复WIN8系统部署带背景的情况下,安装字体读取乱码问题; 2、优化WIN8系统封装部署模块代码; 3、更新程序图标。 Beta1.2.0.1002 ------------------------------------ 1.2.0.1002更新列表 1、调整增强键盘和鼠标驱动从SRS驱动里独立到可选项目; 2、增加赞助商地址为可选设置项目; 3、更新第二次重启的清理子程序代码,主要取消删除部署程序的库文件代码; Beta1.2.0.1001更新列表 ------------------------------------ 修复内测版本所有已知BUG。

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧