//注册表操作
HKEY hKey;
wchar_t content[256]; //所查询注册表键值的内容
DWORD dwType=REG_SZ; //定义读取数据类型
DWORD dwDisposition=256;
DWORD dwLength=256;
struct HKEY__*RootKey; //注册表主键名称
TCHAR *SubKey; //欲打开注册表项的地址
TCHAR *KeyName; //欲设置项的名字
TCHAR *ValueName; //欲设置值的名称
LPBYTE SetContent_S; //字符串类型
int SetContent_D[256]; //DWORD类型
BYTE SetContent_B[256]; //二进制类型int SetValue_S (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,LPBYTE ReSetContent_S);//设置字符串值函数
int SetValue_S (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,LPBYTE ReSetContent_S)
{
int i=0; //操作结果:0==succeed
//int StrLength;
//StrLength=CString(SetContent_S).GetLength(); if(RegOpenKeyEx(ReRootKey,ReSubKey,0,KEY_WRITE,&hKey)==ERROR_SUCCESS)
{
if(RegSetValueEx(hKey,ReValueName,NULL,REG_SZ,ReSetContent_S,CString(SetContent_S).GetLength())!=ERROR_SUCCESS)
{
AfxMessageBox(L"错误:无法设置有关的注册表信息");
i=1;
}
RegCloseKey(hKey);
}
else
{
AfxMessageBox(L"错误:无法查询有关的注册表信息");
i=1;
}
return i;
}
..............(省略内容)void CRegDemoDlg::OnSetValue_S()
{
// TODO: Add your control notification handler code here
RootKey=HKEY_CURRENT_USER; //注册表主键名称
SubKey=L"Software\\Microsoft"; //欲打开注册表值的地址
ValueName=L"例1"; //欲设置值的名称
SetContent_S=LPBYTE(L"成功"); //值的内容
if((SetValue_S(RootKey,SubKey,ValueName,SetContent_S))!=0)
AfxMessageBox(L"操作失败!");
}=========================================================================etContent_S=LPBYTE(L"成功"); 这段在运行程序后... 注册表项内容却只实现 成 缺少功。
还有若改成 英文 情况更糟请问这是为什么?
HKEY hKey;
wchar_t content[256]; //所查询注册表键值的内容
DWORD dwType=REG_SZ; //定义读取数据类型
DWORD dwDisposition=256;
DWORD dwLength=256;
struct HKEY__*RootKey; //注册表主键名称
TCHAR *SubKey; //欲打开注册表项的地址
TCHAR *KeyName; //欲设置项的名字
TCHAR *ValueName; //欲设置值的名称
LPBYTE SetContent_S; //字符串类型
int SetContent_D[256]; //DWORD类型
BYTE SetContent_B[256]; //二进制类型int SetValue_S (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,LPBYTE ReSetContent_S);//设置字符串值函数
int SetValue_S (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,LPBYTE ReSetContent_S)
{
int i=0; //操作结果:0==succeed
//int StrLength;
//StrLength=CString(SetContent_S).GetLength(); if(RegOpenKeyEx(ReRootKey,ReSubKey,0,KEY_WRITE,&hKey)==ERROR_SUCCESS)
{
if(RegSetValueEx(hKey,ReValueName,NULL,REG_SZ,ReSetContent_S,CString(SetContent_S).GetLength())!=ERROR_SUCCESS)
{
AfxMessageBox(L"错误:无法设置有关的注册表信息");
i=1;
}
RegCloseKey(hKey);
}
else
{
AfxMessageBox(L"错误:无法查询有关的注册表信息");
i=1;
}
return i;
}
..............(省略内容)void CRegDemoDlg::OnSetValue_S()
{
// TODO: Add your control notification handler code here
RootKey=HKEY_CURRENT_USER; //注册表主键名称
SubKey=L"Software\\Microsoft"; //欲打开注册表值的地址
ValueName=L"例1"; //欲设置值的名称
SetContent_S=LPBYTE(L"成功"); //值的内容
if((SetValue_S(RootKey,SubKey,ValueName,SetContent_S))!=0)
AfxMessageBox(L"操作失败!");
}=========================================================================etContent_S=LPBYTE(L"成功"); 这段在运行程序后... 注册表项内容却只实现 成 缺少功。
还有若改成 英文 情况更糟请问这是为什么?
解决方案 »
- 在静态成员函数创建线程失败,怎么解决?
- API如何实现透明图片的载入
- 清除Run命令行?微软源代码
- 我有一个很大的循环,里面每格5秒发送一个数据包。我想另外接收数据包,并在界面显示,是不是需要开一个线程?
- 请问lib文件怎么生成,它里面是什么内容,有什么用呢
- 为什么不能调用另一个类的函数?
- 如何将一个结构对象中的数据写入文件中,然后又读出,有什么函数吗?
- 关于一个vc编写的com组件与asp调用的巨普遍的问题
- 如何读取图片的信息头?
- 欢迎老鸟们进来看看:有关位图的缩放
- 如何识别是不是TRUETYPE字体
- CAsynsCosket的基于对话框的通信linsten()函数执行时,会触发系统调用虚函数OnAccept函数吧?
int WideCharToMultiByte(
UINT CodePage, // code page
DWORD dwFlags, // performance and mapping flags
LPCWSTR lpWideCharStr, // wide-character string
int cchWideChar, // number of chars in string.
LPSTR lpMultiByteStr, // buffer for new string
int cbMultiByte, // size of buffer
LPCSTR lpDefaultChar, // default for unmappable chars
LPBOOL lpUsedDefaultChar // set when default char used
);
int ret = RegSetValueEx(hKey, pTmp, NULL, REG_SZ, (LPBYTE)str.GetBuffer(str.GetLength()), strlen(str));
我这样用,就没有问题!
直接改成1024,只要大于ReSetContent_S的实际长度就行
error C2275: “BYTE”: 将此类型用作表达式非法
sorry.笔误
指的是哪个?
这个又回到刚才的情况 就是中文支持好 英文不全BYTE改成w_char试试出错
{
if (NULL == hRootKey ||
NULL == lpszSubKey || '\0' == *lpszSubKey ||
NULL == lpszValueName || '\0' == *lpszValueName ||
NULL == lpszValue)
{
return FALSE;
}
HKEY hkValue;
BOOL bRet = FALSE; //创建注册表键值。
if (RegCreateKey(hRootKey, lpszSubKey, &hkValue) == ERROR_SUCCESS)
{
//向键值写入数据。
bRet = RegSetValueEx(hkValue, lpszValueName, 0, REG_SZ, (CONST BYTE *)lpszValue, (_tcslen(lpszValue) + 1) * sizeof(TCHAR)) == ERROR_SUCCESS;
//关闭键。
RegCloseKey(hkValue);
} return bRet;
}
{
if(RegSetValueEx(hKey,ReValueName,NULL,REG_SZ,CString(ReSetContent_S),CString(SetContent_S).GetLength())!=ERROR_SUCCESS)
{
AfxMessageBox(L"错误:无法设置有关的注册表信息");
i=1;
}
RegCloseKey(hKey);
}
else
{
AfxMessageBox(L"错误:无法查询有关的注册表信息");
i=1;
}
return i;
,要是多字节的就没有,如果是多字节的最后个参数就要填大一点!!!