Hello. Maybe someone can help me with this, here is my code:
#include <windows.h>
#include <stdio.h>
#include <wininet.h>
#include <shlwapi.h>
#define mb(x,z) MessageBox(0,x,z,0)
#define REGKEY "PATH\\to\\my\\key"
#define REGNAME "zzzzzzzzzzzzz"
#define EXENAME "zzzzzz.exe"
void Reg()
{
HKEY hkey;
DWORD dwDisposition;
DWORD m_dwMaxFileSize = 16 * 1024;
TCHAR m_szLastFileName[MAX_PATH];
DWORD dwType, dwSize;
int data = 10;
char somechar[MAX_PATH];
strcpy(somechar, "somechar");
strcpy(m_szLastFileName, TEXT("Datafile.TXT"));
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("PATH\\to\\my\\key\\zzzz"), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)== ERROR_SUCCESS)
{
RegSetValueEx(hkey, REGNAME, 0, REG_SZ, (LPSTR)somechar, strlen(somechar));
RegSetValueEx(hkey, NULL, 0, REG_SZ,
(BYTE *)data,
sizeof(data)+1) ;
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
if(RegSetValueEx(hkey, TEXT("MaxFileSize"), 0, dwType,
(PBYTE)&m_dwMaxFileSize, dwSize) != ERROR_SUCCESS) mb("error","");
dwType = REG_SZ;
dwSize = (strlen(m_szLastFileName) + 1) * sizeof(TCHAR);
if(RegSetValueEx(hkey, TEXT("LastFileName"), 0, dwType,
(PBYTE)&m_szLastFileName, dwSize) != ERROR_SUCCESS) mb("errorr","");
RegCloseKey(hkey);
}
}
int main(int argc, char *argv[]){
Reg();
}
and it is not working no matter what. Its combination of code from microsoft site and some my own. That progie only creates key, and after that crashes. If key is already in registry, then its not crashes but not adding values either. The same issue i got with RegDeleteValue function, which doesnot deleting values in my case.
The only function wich is working for me is:
SHDeleteKey...
Maybe someone can point me to some tut about shell registry functions, but not msdn, there aren't any examples ;p