c++ , how to delete a binary key in the registry

Posted By: ello

c++ , how to delete a binary key in the registry - 12/04/10 16:23

hi there,
can someone point me to how i can delete a certain binary entry in the registry? i can delete a whole key with its content but i cant find some example or info how to delete a certain binary entry...

for example how can i delete HKEY_LOCAL_MACHINE\\SOFTWARE\\MYKEY\\VALUE

thanks in advance,
ello

edit: ok, i found this RegDeleteKeyValue.. but how do i use it? i gent an error "error C2664: 'RegDeleteKeyValueW': Konvertierung des Parameters 2 von 'const char [33]' in 'LPCWSTR' nicht möglich"

this is how iwas trying it:
RegDeleteKeyValue(HKEY_LOCAL_MACHINE,"HKEY_LOCAL_MACHINE\\SOFTWARE\\MYKEY","VALUE");

Posted By: muffel

Re: c++ , how to delete a binary key in the registry - 12/04/10 17:43

put a L in front of the string

muffel
Posted By: TechMuc

Re: c++ , how to delete a binary key in the registry - 12/04/10 18:30

or make an ascii build instead of an unicode one..
Posted By: ello

Re: c++ , how to delete a binary key in the registry - 12/04/10 20:20

thanks for you r help.. what could it be that the value isnt deleted? i have created the value manually in the registry for testing purposes and when i run my program the value still remains.

here is my complete code:
Code:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])
{

CHAR strLong[1024];
	LONG result;
	result = RegDeleteKeyValue(HKEY_LOCAL_MACHINE,L"SOFTWARE\\MYKEY\\",L"VALUE");

   printf(strLong, "%s", result);
   printf("\n");
   system("Pause");
return 0;
}



thanks in advance for any help

edit:
i tried another way
Code:
#include <stdio.h>
#include <windows.h>

int main()
{
	HKEY hkey;
	LONG result;
	result = RegOpenKey(HKEY_LOCAL_MACHINE, L"SOFTWARE\\MYKEY", &hkey);
	if(result==ERROR_SUCCESS) printf("key opened");
	RegDeleteValue(hkey, L"VALUE");
	RegCloseKey(hkey);
	system("Pause");
	return 0;
}


it seems that the key isnt even opened as the printf is not called.

any ideas??
Posted By: ello

Re: c++ , how to delete a binary key in the registry - 12/04/10 22:26

hi there.. i have updated the code to get better info about the error
Code:
#include <stdio.h>
#include <windows.h>
int main()
{
	LONG result;
	result = RegDeleteKeyValue(HKEY_LOCAL_MACHINE,L"/SOFTWARE/MYKEY",L"VALUE");
	LPVOID lpMsgBuf;
	FormatMessage( 
		FORMAT_MESSAGE_ALLOCATE_BUFFER | 
		FORMAT_MESSAGE_FROM_SYSTEM | 
		FORMAT_MESSAGE_IGNORE_INSERTS,
		NULL,
		result,
		0, 
		(LPTSTR) &lpMsgBuf,
		0,
		NULL 
		);
	MessageBox( NULL, (LPCTSTR)lpMsgBuf, L"Error", MB_OK | MB_ICONINFORMATION );
	LocalFree( lpMsgBuf );

	return 0;
}



and i am getting "Das System konnte die angegebene Datei nicht finden"

any ideas??
© 2024 lite-C Forums