I'd like to get an opinion and feedback, correction on my win32 C program RRS feed

  • Question

  • Where could i get help and which forum to use:

    I have this C program I have been working on, and I'd like to be checked if the code is properly written, does not contain a lot of mistakes, and conforms correctly to the Microsoft's documentation (

        DWORD BufferSize;
        HKEY    hkey     = HKEY_LOCAL_MACHINE;
        LPCSTR  lpSubKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
        LPCSTR  lpValue  = "Path";
        DWORD   dwFlags  = RRF_RT_ANY;
        LPDWORD pdwType  = NULL;
        PVOID   pvData   = NULL;
        LPDWORD pcbData  = &BufferSize;
    	// First, RegGetValueA retrieves pcbData, which contains size of pvData in bytes
        RegGetValueA(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData);
    	// Allocate Memory for pvData
        pvData = (int*)malloc(*pcbData);
    	// Second, RegGetValueA retrieves pvData, which contains path variable value
        RegGetValueA(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData);
            printf("  Retrieved information about array size: %i\n",*pcbData);
            printf("  Actual size of the array: %i\n", strlen(pvData));
            printf("  Manually Allocated bytes for the array: %zu", sizeof(pvData));
            printf("\n  (Since malloc was used, the dynamic Allocation makes the Manual Allocation results strange.)\n");
            //        //

    Saturday, October 24, 2020 9:54 AM


All replies