SoloCodigo

Programación General => C/C++ => Visual C++ => Mensaje iniciado por: Geo en Jueves 28 de Diciembre de 2006, 06:19

Título: Problema Con El Registro
Publicado por: Geo en Jueves 28 de Diciembre de 2006, 06:19
Qué tal, tengo problemas para poder actualizar una clave del registro de Windows. Este es mi código:

Citar
TCHAR buffer[ MAX_PATH ];
wsprintf( buffer, L"ControlPanel\\Desktop" );

HKEY hKey;
LONG open;

open = RegOpenKeyEx(
   HKEY_CURRENT_USER, buffer,
   0, KEY_WRITE, &hKey
);

if ( open != ERROR_SUCCESS ) {
   showError();
   //return false;
}

RegSetValueEx( hKey, L"WallpaperStyle", 0, REG_SZ, (LPBYTE)"0", lstrlen( L"0" ) + 1 );
RegSetValueEx( hKey, L"TileWallpaper", 0, REG_SZ, (LPBYTE)"0", lstrlen( L"0" ) + 1 );
Pero no logro que las claves se actualicen, siempre conservan su valor. El único detalle que he encontrado es que en la variable open me aparece un valor de error que con la función showError() me muestra Error 183: No se puede crear un archivo que ya existe.. Lo que no entiendo es porqué indica eso si se supone que la función RegOpenKeyEx no crea la clave sino simplemente la abre:
Citar
Remarks
Unlike the RegCreateKeyEx function, the RegOpenKeyEx function does not create the specified key if the key does not exist in the registry.

La función showError:
Código: Text
  1.  
  2. void showError() {
  3.     TCHAR szBuf[80];
  4.     LPVOID lpMsgBuf;
  5.     DWORD dw = GetLastError();
  6.  
  7.     FormatMessage(
  8.         FORMAT_MESSAGE_ALLOCATE_BUFFER |
  9.         FORMAT_MESSAGE_FROM_SYSTEM,
  10.         NULL,
  11.         dw,
  12.         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  13.         (LPTSTR) &lpMsgBuf,
  14.         0, NULL
  15.   );
  16.  
  17.     wsprintf(
  18.     szBuf,
  19.         L"Error %d: %s",
  20.         dw, lpMsgBuf
  21.   );
  22.  
  23.     MessageBox(NULL, szBuf, L"Error", MB_OK);
  24. }
  25.  
  26.  
Gracias de antemano :).
Título: Re: Problema Con El Registro
Publicado por: Eternal Idol en Jueves 28 de Diciembre de 2006, 10:43
Jeje, Control Panel, con espacio  :P
Título: Re: Problema Con El Registro
Publicado por: Geo en Jueves 28 de Diciembre de 2006, 17:45
Cita de: "Eternal Idol"
Jeje, Control Panel, con espacio  :P
¡Aaaargh! :brickwall:  :argh:

:gracias:
JJ (Geo).