本文整理汇总了C++中atl::CRegKey::SetMultiStringValue方法的典型用法代码示例。如果您正苦于以下问题:C++ CRegKey::SetMultiStringValue方法的具体用法?C++ CRegKey::SetMultiStringValue怎么用?C++ CRegKey::SetMultiStringValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atl::CRegKey
的用法示例。
在下文中一共展示了CRegKey::SetMultiStringValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetStringArrayIntoRegistry
BOOL CNTEventLogSource::SetStringArrayIntoRegistry(ATL::CRegKey& key, LPCTSTR lpszEntry, const CNTServiceStringArray& array, DWORD* pLastError)
{
//Validate our input parameters
ATLASSERT(lpszEntry != NULL);
//Work out the size of the buffer we will need
#ifdef CNTSERVICE_MFC_EXTENSIONS
int nSize = 0;
INT_PTR nStrings = array.GetSize();
for (INT_PTR i=0; i<nStrings; i++)
nSize += array.GetAt(i).GetLength() + 1; //1 extra for each NULL terminator
#else
CNTServiceStringArray::size_type nSize = 0;
CNTServiceStringArray::size_type nStrings = array.size();
for (CNTServiceStringArray::size_type i=0; i<nStrings; i++)
nSize += array[i].length() + 1; //1 extra for each NULL terminator
#endif
//Need one second NULL for the double NULL at the end
nSize++;
//Allocate some memory for the API
ATL::CHeapPtr<TCHAR> lpBuffer;
if (!lpBuffer.Allocate(nSize))
{
SetLastError(ERROR_OUTOFMEMORY);
if (pLastError)
*pLastError = ERROR_OUTOFMEMORY;
return FALSE;
}
//Now copy the strings into the buffer
LPTSTR lpszString = lpBuffer.m_pData;
#ifdef CNTSERVICE_MFC_EXTENSIONS
int nCurOffset = 0;
for (INT_PTR i=0; i<nStrings; i++)
#else
CNTServiceStringArray::size_type nCurOffset = 0;
for (CNTServiceStringArray::size_type i=0; i<nStrings; i++)
#endif
{
const CNTServiceString& sText = array[i];
#ifdef CNTSERVICE_MFC_EXTENSIONS
int nCurrentStringLength = sText.GetLength();
_tcscpy_s(&lpszString[nCurOffset], nCurrentStringLength+1, sText);
#else
CNTServiceString::size_type nCurrentStringLength = sText.length();
_tcscpy_s(&lpszString[nCurOffset], nCurrentStringLength+1, sText.c_str());
#endif
nCurOffset += (nCurrentStringLength + 1);
}
//Don't forgot to doubly NULL terminate
lpszString[nCurOffset] = _T('\0');
//Finally write it into the registry
LONG lResult = key.SetMultiStringValue(lpszEntry, lpBuffer);
BOOL bSuccess = (lResult == ERROR_SUCCESS);
if (!bSuccess && pLastError)
*pLastError = lResult;
return bSuccess;
}
示例2: CreateGreenShieldService
HRESULT CreateGreenShieldService(const wchar_t* szDllPath)
{
TSAUTO();
SC_HANDLE schSCManager = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (schSCManager == NULL) {
DWORD dwOpenError = ::GetLastError();
TSERROR4CXX("OpenSCManager failed. Error: " << dwOpenError);
return HRESULT_FROM_WIN32(dwOpenError);
}
ScopeResourceHandle<SC_HANDLE, BOOL (WINAPI*)(SC_HANDLE)> autoCloseSCManagerHandle(schSCManager, ::CloseServiceHandle);
const wchar_t* szImagePath = L"%SystemRoot%\\System32\\svchost.exe -k ADCleanService";
SC_HANDLE schService = ::CreateService(
schSCManager,
szServiceName,
szServiceName,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_SHARE_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
szImagePath,
NULL,
NULL,
NULL,
NULL,
NULL);
if(schService == NULL) {
DWORD dwCreateError = ::GetLastError();
TSERROR4CXX("CreateService failed. Error: " << dwCreateError);
return HRESULT_FROM_WIN32(dwCreateError);
}
ScopeResourceHandle<SC_HANDLE, BOOL (WINAPI*)(SC_HANDLE)> autoCloseServiceHandle(schService, ::CloseServiceHandle);
SERVICE_DESCRIPTION description = { L"广告清道夫实时过滤服务。" };
ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &description);
// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\ADCleanService
ATL::CRegKey key;
LONG lRegResult = key.Open(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\services\\ADCleanService", KEY_READ);
if(lRegResult != ERROR_SUCCESS) {
TSERROR4CXX("Filed to open reg key. Key: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\ADCleanService. Error: " << lRegResult);
return HRESULT_FROM_WIN32(lRegResult);
}
key.Close();
// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\ADCleanService\Parameters
lRegResult = key.Create(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\services\\ADCleanService\\Parameters");
if(lRegResult != ERROR_SUCCESS) {
TSERROR4CXX("Failed to create reg key. Key: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\ADCleanService\\Parameters. Error: " << lRegResult);
return HRESULT_FROM_WIN32(lRegResult);
}
lRegResult = key.SetStringValue(L"ServiceDll", szDllPath, REG_EXPAND_SZ);
if(lRegResult != ERROR_SUCCESS) {
TSERROR4CXX("Failed to set reg value. Key: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\ADCleanService\\Parameters\\ServiceDll. Error: " << lRegResult);
return HRESULT_FROM_WIN32(lRegResult);
}
key.Close();
// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Svchost
lRegResult = key.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost");
if(lRegResult != ERROR_SUCCESS) {
TSERROR4CXX("Failed to open reg key. Key: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost. Error: " << lRegResult);
return HRESULT_FROM_WIN32(lRegResult);
}
lRegResult = key.SetMultiStringValue(L"ADCleanService", L"ADCleanService\0");
if(lRegResult != ERROR_SUCCESS) {
TSERROR4CXX("Failed to set reg value. Key: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost\\ADCleanService. Error: " << lRegResult);
return HRESULT_FROM_WIN32(lRegResult);
}
// start service
::StartService(schService, 0, NULL);
return S_OK;
}