Archive for January, 2009


image

I got this thread from one of my senior, while discussing about our project. Till then, I didn’t noticed any differences between SHCreateDirectoryEx() and CreateDirectory(). But now.. Yes its is.. some .. lil difference is there.

just look at the function call

for eg:

if (CreateDirectory(“c:\\Test\\Test\\Test\\Test”,NULL))
        AfxMessageBox(“Created “);

if (ERROR_SUCCESS == SHCreateDirectoryEx(NULL,”c:\\Test\\Test\\Test\\Test”,NULL))
{
    AfxMessageBox(“Created”);
}

description from MSDN is like that for SHCreateDirectoryEX()

int SHCreateDirectoryEx(HWND hwnd, LPCTSTR pszPath, SECURITY_ATTRIBUTES *psa);

BOOL CreateDirectory(LPCTSTR lpPathName,LPSECURITY_ATTRIBUTES lpSecurityAttributes );

This function creates a file system folder whose fully qualified path is given by pszPath. If one or more of the intermediate folders do not exist, they will be created as well.

for CreateDirectory() the description is like this “ This function creates a new directory”

 

Hope now you noticed the difference from the description itself. 🙂

 

 

True commitment begins when we decide to do it anyway.

for https://vctipsplusplus.wordpress.com/

BijU

🙂

The Windows registry is a database which stores settings and options for the operating system for Microsoft Windows 32-bit versions, 64-bit versions and Windows Mobile. It contains information and settings for all the hardware, software, users, and preferences of the PC. Whenever a user makes changes to “Control Panel” settings, or file associations, system policies, or installed software, the changes are reflected and stored in the registry.

image

Class CRegKey provides methods for manipulating values in the system registry.

Now I’m just explaining how to manipulate the Windows Registry using CRegkey Class.

How can we read/modify the data using CRegkey Class ?

You can read data from the registry using the following function

DWORD CRegTest::GetRegistryValue(LPCSTR lpSubKey,LPCSTR lpzValue,LPBYTE* pData)
{
HKEY hKey;
LONG iSuccess;
DWORD dwType=REG_BINARY;
DWORD dwSize=1024;

iSuccess = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0L,  KEY_ALL_ACCESS, &hKey);
if (iSuccess == ERROR_SUCCESS)
{
iSuccess = RegQueryValueEx(hKey, lpzValue, NULL, &dwType,NULL, &dwSize);
*pData = new BYTE[dwSize];
iSuccess = RegQueryValueEx(hKey, lpzValue, NULL, &dwType,*pData, &dwSize);
if (iSuccess == ERROR_SUCCESS)
{
return dwSize;
}
else
{
return 0;
}

}

RegCloseKey(hKey);

return 0;
}

Also, You can write data to the registry using the following function

void CRegTest::SetRegistry(LPCSTR lpRegistryKey,LPCSTR lpzValue,LPVOID lpData,DWORD dwSize)
{
// Add your source name as a subkey under the Application
HKEY hKey;
DWORD dwDisp = 0;
LPDWORD lpdwDisp = &dwDisp;
LONG iSuccess = RegCreateKeyEx( HKEY_LOCAL_MACHINE, lpRegistryKey, 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);

if(iSuccess == ERROR_SUCCESS)
{
if (iSuccess = RegSetValueEx(hKey,             // subkey handle
lpzValue,       // value name
0,                        // must be zero
REG_BINARY,            // value type
(BYTE*)lpData,dwSize))
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, “Error”, MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );

}
}
RegCloseKey(hKey);
}

OK..? Any doubts??

Then you can call the function like..

TCHAR lpRegistryKey[]     = _T(“SOFTWARE\\TestReg\\KeyVal”);
TCHAR lpzLicValue[]      = (“Key”);
TCHAR lpzModeValue[]     = (“Value”);
BYTE* pbRegVal = NULL;

DWORD dwDataLen1 = SetRegistryValue(lpRegistryKey,lpzLicValue,&pbRegVal);
if(0 == dwDataLen1)
return false;

// Now pbRegVal contains the data from the registry

// Delete the allocated memory
if (pbRegVal)
{
delete[] pbRegVal;
}

BYTE* pbData = NULL;
DWORD dwDataLen = GetRegistryValue(lpRegistryKey,lpzValue,&pbData);
// Now pbData contains the data from the registry

// Delete the allocated memory
if(pbData)
delete[] pbData;

ho..what a simple process na??

🙂

Weakness of attitude becomes Weakness of character.

for https://vctipsplusplus.wordpress.com/

BijU

)