[C] error while writting in the registry (DWORD)

This is a discussion on [C] error while writting in the registry (DWORD) within the Windows Programming forums, part of the Platform Specific Boards category; hi the problem is not how to write in the registry but it seems a funcion error or some crap ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    161

    [C] error while writting in the registry (DWORD)

    hi

    the problem is not how to write in the registry but it seems a funcion error or some crap like that... I wrote my insertkey(..) function that fails writting the valuedata (it writes only c:\F instead c:\File.exe)

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    
    int insertkey(char key[], char valuename[], char valuedata[]);
    
    int main(void)
    
    {
    
    ..
    ..
    
    insertkey("SYSTEM\\List\\",
                          "C:\\file.exe",                     
                          "C:\\file.exe")
    
    ..
    ..
    
    }
    
    int insertkey(char key[], char valuename[], char valuedata[])
         
    {
        HKEY hKey;
        DWORD dwDisposition;
        
        RegCreateKeyEx(HKEY_LOCAL_MACHINE, key, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
        RegSetValueEx(hKey, valuename, 0, REG_SZ, (LPBYTE)valuedata, sizeof(valuedata));
        RegCloseKey(hKey);
        return 0;
    
    }
    at the end i have the key, the valuename but the value data is not c:\file.exe but it is c:\f

    i think the problem is char valuedata[] because the regsetvalueex wants a DWORD but how to give to the funcion a DWORD? I never did that...
    This forum is the best one I've ever seen. Great ppl, great coders

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    sizeof(valuedata)
    sizeof on a pointer will give the value 4 on 32 bit windows. You need to use strlen:
    Code:
    (lstrlen(valuedata) + 1) * sizeof(TCHAR)
    Windows provides a function similar to your insertkey() in the form of SHSetValue().

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    ah.. the lenght of the string * the lenght of a char..

    the +1 is for the '\0' (end string)?

    thanx!
    This forum is the best one I've ever seen. Great ppl, great coders

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 04:48 PM
  2. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 02:54 PM
  3. Getting position from game..
    By brietje698 in forum C++ Programming
    Replies: 1
    Last Post: 10-26-2007, 01:15 PM
  4. Writting to registry failling
    By Joelito in forum Windows Programming
    Replies: 4
    Last Post: 04-11-2006, 01:38 PM
  5. storage size of regs is unkown
    By Vertex34 in forum C Programming
    Replies: 5
    Last Post: 11-04-2003, 10:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21