#include <windows.h>
#include <Winerror.h>
#include <iostream>
using namespace std;#pragma comment (lib, "Advapi32.lib")int main()
{
HKEY RootKey = HKEY_LOCAL_MACHINE;  // 访问的key
HKEY OperateKey;                    // 需要进行操作的key
LPCWSTR SubKey = TEXT("Software\Microsoft\Windows\CurrentVersion");  // 子key
LPCWSTR ValueName = TEXT("SM_GamesName");   // value的名称
LONG ERROR_FLAG;                    // 错误标志
LPBYTE data = 0;
LPDWORD length = 0;  ERROR_FLAG = RegOpenKeyEx( RootKey,SubKey ,0,KEY_ALL_ACCESS,&OperateKey );
if ( ERROR_FLAG != ERROR_SUCCESS )
{
cerr <<"打开注册表失败1" <<endl;
cerr <<"code "<<ERROR_FLAG;
return 1;
}
return 0;
}我现在只是试验了打开操作,但是返回失败,error值为2,我查了一下,表示文件错误。
我参考了msdn,函数使用,参数传递都没有错误,那位能帮我看一下,到底是什么地方有错误?