【HELP】RegSetValueEx使用问题,VALUE类型为REG_DWORD

qq1061006 2010-11-25 08:15:20
////////省略//////////////
DWROD valuedata=1;
DWORD datasize=sizeof(valuedata);
RegSetValueEx(hKey,"dword value",0,REG_DWORD,(CONST BYTE *)valuedata,datasize);


调用RegSetValueEx返回 ERROR_SUCCESS,但是键值并没有设置成功。。 请问问题出在哪里?
...全文
511 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
龙哥依旧 2010-11-25
  • 打赏
  • 举报
回复
具体问题要具体分析
#include <stdafx.h>
#include <windows.h>
#include <iostream>
#include <strsafe.h>

int __cdecl wmain(int argc, LPWSTR *argv)
{
// Name of the event log.
wchar_t *logName = L"Application";
// Event Source name.
wchar_t *sourceName = L"SampleEventSourceName";
// DLL that contains the event messages (descriptions).
wchar_t *dllName = L"C:\\WINDOWS\\SYSTEM32\\eventSource.dll";
// This number of categories for the event source.
DWORD dwCategoryNum = 1;

HKEY hk;
DWORD dwData, dwDisp;
TCHAR szBuf[MAX_PATH];
size_t cchSize = MAX_PATH;

// Create the event source as a subkey of the log.
HRESULT hr = StringCchPrintf(szBuf, cchSize,
L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s",
logName, sourceName);

if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szBuf,
0, NULL, REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &hk, &dwDisp))
{
printf("Could not create the registry key.");
return 0;
}

// Set the name of the message file.

if (RegSetValueEx(hk, // subkey handle
L"EventMessageFile", // value name
0, // must be zero
REG_EXPAND_SZ, // value type
(LPBYTE) dllName, // pointer to value data
(DWORD) (lstrlen(dllName)+1)*sizeof(TCHAR))) // data size
{
printf("Could not set the event message file.");
RegCloseKey(hk);
return 0;
}

// Set the supported event types.

dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
EVENTLOG_INFORMATION_TYPE;

if (RegSetValueEx(hk, // subkey handle
L"TypesSupported", // value name
0, // must be zero
REG_DWORD, // value type
(LPBYTE) &dwData, // pointer to value data
sizeof(DWORD))) // length of value data
{
printf("Could not set the supported types.");
RegCloseKey(hk);
return 0;
}

// Set the category message file and number of categories.

if (RegSetValueEx(hk, // subkey handle
L"CategoryMessageFile", // value name
0, // must be zero
REG_EXPAND_SZ, // value type
(LPBYTE) dllName, // pointer to value data
(DWORD) (lstrlen(dllName)+1)*sizeof(TCHAR))) // data size
{
printf("Could not set the category message file.");
RegCloseKey(hk);
return 0;
}

if (RegSetValueEx(hk, // subkey handle
L"CategoryCount", // value name
0, // must be zero
REG_DWORD, // value type
(LPBYTE) &dwCategoryNum, // pointer to value data
sizeof(DWORD))) // length of value data
{
printf("Could not set the category count.");
RegCloseKey(hk);
return 0;
}

RegCloseKey(hk);
return 1;
}


如果这个可以,对照一下是哪里出的问题
smallfishff 2010-11-25
  • 打赏
  • 举报
回复
BYTE valuedata=1;
DWORD datasize=1;

RegSetValueEx(hKey,"dword value",0,REG_DWORD,&valuedata,datasize);

这样试试看.

你要确定有"dword value"这个字段.不过如果返回了ERROR_SUCCESS还没有看到值的话那还比较奇怪.

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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