各位大侠,近日在做一个开机自动运行的程序,网上也有很多例子,但是发现我在UINICODE工程系写进去的注册表信息不全,少了一半。
贴上代码:
TCHAR pszValue[50] = {0} ;
_tcscpy(pszValue , TEXT("TATA 3G Photon Plus")) ;
TCHAR *pRegPath = TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
HMODULE hModule=NULL;
TCHAR svFileName[512], svFullPath[524];
memset(svFileName,'\0',512);
memset(svFullPath,'\0',524);
::GetModuleFileName(hModule,svFileName,512);
MessageBox(NULL,svFileName,_T("当前目录"),MB_OK);
wsprintf(svFullPath,_T("\"%s\""),svFileName);
MessageBox(NULL,svFullPath,_T("当前目录"),MB_OK); HKEY hKey ;
long lRet = RegOpenKey(HKEY_LOCAL_MACHINE,pRegPath,&hKey) ;
if(!bRunFlag)
{
RegDeleteValue(hKey,pszValue) ;
RegCloseKey(hKey);
return ;
}
else
{
DWORD Reserved=0; // reserved
DWORD dwType = REG_SZ; // flag for value type
lRet = RegSetValueEx(hKey,pszValue, Reserved, dwType, (BYTE*)svFullPath,lstrlen(svFullPath) );
RegCloseKey(hKey);
}
请大虾们赐教!
MessageBox打印出来的信息是完整的!
但是注册表里面信息就少了一半!microsoftwindowsbyte
贴上代码:
TCHAR pszValue[50] = {0} ;
_tcscpy(pszValue , TEXT("TATA 3G Photon Plus")) ;
TCHAR *pRegPath = TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
HMODULE hModule=NULL;
TCHAR svFileName[512], svFullPath[524];
memset(svFileName,'\0',512);
memset(svFullPath,'\0',524);
::GetModuleFileName(hModule,svFileName,512);
MessageBox(NULL,svFileName,_T("当前目录"),MB_OK);
wsprintf(svFullPath,_T("\"%s\""),svFileName);
MessageBox(NULL,svFullPath,_T("当前目录"),MB_OK); HKEY hKey ;
long lRet = RegOpenKey(HKEY_LOCAL_MACHINE,pRegPath,&hKey) ;
if(!bRunFlag)
{
RegDeleteValue(hKey,pszValue) ;
RegCloseKey(hKey);
return ;
}
else
{
DWORD Reserved=0; // reserved
DWORD dwType = REG_SZ; // flag for value type
lRet = RegSetValueEx(hKey,pszValue, Reserved, dwType, (BYTE*)svFullPath,lstrlen(svFullPath) );
RegCloseKey(hKey);
}
请大虾们赐教!
MessageBox打印出来的信息是完整的!
但是注册表里面信息就少了一半!microsoftwindowsbyte
lstrlen那错了,因为是unicode,所以字节数应该是字符串长度×2