wince 和win2000导出的注册表文件分析

王朝vc·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

RegSetValueEx()

If dwType is the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type and the ANSI version of this function is used (either by explicitly calling RegSetValueExA or by not defining UNICODE before including the WINDOWS.H file), the data pointed to by the lpData parameter must be an ANSI character string. The string is converted to Unicode before it is stored in the registry.

但是在wince平台,和PC机上导出来的reg文件的最终格式是一样的。如:

"vaule" = hex(7):31,00,30,00,2e,00,36,00,2e,00,39,00,39,00,2e,00,31,00,31,00,30,00,31,00,30,00,2e,00,36,00,2e,00,39,00,39,00,2e,00,31,00,31,00,31,00,00,00,00,00

这是一个REG_MULTI_SZ类型的注册表值。31,00为一个字符。30,00为一个字符。其它类似。31,00.....的个数可以被4整除。REG_MULTI_SZ类型的注册表值是由多个以00,00结尾的字符串组成。在最后面。是两个00,00.相当于在最后一个字符串后面又加了一个00,00。

在Wince上导入时,可以把31合到一个字节中,再把00合到一个字节中。在pc中,则是把31,00合到一个字节中。因为在wince中是unicode,在PC上是ANSI。

"新值 #1"=hex(7):11,62,31,00,00,00,00,00这个其键值表示的是:我1。

其中我===>11,62 1==>31,00为unicode编码。

这个如果想到得到其byte形式,则要调函数进行转换。从unicode转换成char的形式后,才可在PC机上向注册表中写。

int n;

n = WideCharToMultiByte(CP_ACP, 0, (WCHAR*)pbData, nWchar, 0, 0,NULL,NULL);

char* buf = new char[n+1];

memset(buf, 0, n+1);

int nWrite = WideCharToMultiByte(CP_ACP, 0, (WCHAR*)pbData, nWchar, buf, n,NULL,NULL);

if(nWrite != n)

{

AfxMessageBox("WideCharToMultiByte error");

}

RegSetValueEx(m_hKey, strValue, NULL, dwType, (const unsigned char*)buf, n);

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航