vs c++ C2664 cannot convert parameter from 'const wchar_t' to 'LPCWSTR'-Collection of common programming errors

I’m new to c++. Coding in VS Express 2012 with Update 1. OS is Win 7 Ultimate SP1 x86.

For the code below, which is the contents of main.cpp (I’ve put under Source Files), I get the following errors:

Error 2 error C2664: ‘RegSaveKeyW’ : cannot convert parameter 2 from ‘wchar_t’ to ‘LPCWSTR’ \registrybackup_test\registrybackup_test\main.cpp 17 1 RegistryBackup_test

Error 1 error C2440: ‘initializing’ : cannot convert from ‘const wchar_t [40]’ to ‘wchar_t’ \registrybackup_test\registrybackup_test\main.cpp 13 1 RegistryBackup_test

I’ve googled the error codes 2664 & 2440, but this hasn’t helped me since they were using different functions and often different datatypes for the strings they were trying to convert from and to.

The “ScopedPrivilege” class allows the privilege in the () to be used in the code following it. – This class has been tested & working fine.

I’ve used the SE_BACKUP_NAME privilege since it’s what is needed for backing up the registry.

I’m seeking assistance on what I need to change / add in to the code to make code build without errors, while keeping my aim (to backup a registry hive)?

Thank you.

#include 
#include "LogCommon/ScopedPrivilege.hpp"
#include "LogCommon/Win32Exception.hpp"
//using namespace std;

using abcdefg::SystemFacades::ScopedPrivilege;
using abcdefg::SystemFacades::Win32Exception;

//namespace abcdefg { namespace SystemFacades {

int main() {
//wchar_t lresult;
wchar_t file1 = L"c:\\abcdefgRegBackup\\backup00X_yyyymmdd";
//const wchar_t file1 = L"c:\\abcdefgRegBackup\\backup00X_yyyymmdd";
wchar_t lresult;
ScopedPrivilege guard(SE_BACKUP_NAME);
lresult = RegSaveKeyW(HKEY_CLASSES_ROOT, file1, 0);
//lresult = RegSaveKeyW(HKEY_CLASSES_ROOT, LPWSTR"c:\\abcdefgRegBackup\\backup00X_yyyymmdd", 0);
//lresult = RegSaveKeyW(HKEY HKEY_CLASSES_ROOT, LPCTSTR L"c:\\abcdefgRegBackup\\backup00Xyyyymmdd", LPSECURITY_ATTRIBUTES 0);

/*
LPSTR = char*
LPCSTR = const char*
LPWSTR = wchar_t*
LPCWSTR = const wchar_t*
LPTSTR = char* or wchar_t* depending on _UNICODE
LPCTSTR = const char* or const wchar_t* depending on _UNICODE
*/

if (lresult = ERROR_SUCCESS)                    {
        //  File saved successfully
}

else {
        if (lresult = ERROR_ALREADY_EXISTS) {
            // File with that name already exists !
            // Want to ask user to either overwrite file, or choose another location to save
            // Win32Exception::ThrowFromLastError();
        }

        else                                {
            // Unknown error - show what this is.
            Win32Exception::ThrowFromLastError();
        }
    }   
return 0;

}

Originally posted 2013-11-23 19:34:01.