In buona sostanza è il conteggio dei byte necessari a memorizzare la stringa(compreso il carattere terminatore '\0').
Puoi ottenerlo così:
codice:
(_tcslen(data) + 1) * sizeof(TCHAR)
Esempio:
codice:
#include "windows.h"
int _tmain(int argc, _TCHAR* argv[])
{
LPCTSTR RegValue = TEXT("myKey");
LPCTSTR data = TEXT("C:\\Windows\\prova.exe");
HKEY hKey;
LPCTSTR sk = TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
LONG Res = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS , &hKey);
if ( Res != ERROR_SUCCESS )
{
printf("Errore nell'apertura della chiave del registro.\n");
return -1;
}
Res = RegSetValueEx(hKey, RegValue, 0, REG_SZ, (LPBYTE)data, (_tcslen(data) + 1) * sizeof(TCHAR));
if ( Res != ERROR_SUCCESS )
{
printf("Errore nella scrittura dei dati nella chiave del registro.\n");
return -1;
}
return 0;
}