-2

I have written a C++ program in Code::Blocks which reads REG_NONE type value from registry.

Here are my codes:

#define KEY_WOW64_64KEY 0x0100
#include "string"
#include "windows.h"
using namespace std;

int main()
{
    HKEY hKey;
    long longErrorCode;
    string strErrorCaption = "Hata";
    string strErrorMessage;
    string strSubKey = "Software\\DownloadManager\\Scheduler";

    longErrorCode = RegOpenKeyEx(HKEY_CURRENT_USER, strSubKey.c_str(), 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey);

    if (longErrorCode != ERROR_SUCCESS)
    {
        strErrorMessage = "Anahtar açılamadı.";

        MessageBox(NULL, strErrorMessage.c_str(), strErrorCaption.c_str(), MB_OK | MB_ICONERROR);

        return 0;
    }

    else
    {
        DWORD dwSize = MAX_PATH;
        DWORD dwValueContent;
        DWORD dwValueType = REG_NONE;
        string strValueName = "startDay";

        longErrorCode = RegQueryValueEx(hKey, strValueName.c_str(), 0, &dwValueType, (LPBYTE)&dwValueContent, &dwSize);

        if (longErrorCode != ERROR_SUCCESS)
        {
            RegCloseKey(hKey);

            strErrorMessage = "Değer açılamadı.";

            MessageBox(NULL, strErrorMessage.c_str(), strErrorCaption.c_str(), MB_OK | MB_ICONERROR);

            return 0;
        }

        else
        {
            string strValueContent = to_string(dwValueContent);

            RegCloseKey(hKey);

            strErrorCaption = "Başarılı!";

            MessageBox(NULL, strValueContent.c_str(), strErrorCaption.c_str(), MB_OK | MB_ICONINFORMATION);

            return 0;
        }
    }
}

The real value of the registry key which I tried to read is "f5 68 4b 5c".

But the problem is I got "1548445941". I also tried stringstream; but it didn't work.

So, what should I do in order to fix this issue?

drescherjm
  • 10,365
  • 5
  • 44
  • 64

2 Answers2

2

the number is correct when you notice the bytes are ordered from the lower to the upper bytes.

Hex 5C4B68F5 = dec 1548445941
matzeri
  • 8,062
  • 2
  • 15
  • 16
  • Thank you; but I quit from this site due to members' of the site hate newbies, I presume. I did not even any punctuation error. I wrote everything correctly; but I got "-2" vote. Seriously? What the hell should I do to be accepted? –  Jan 26 '19 at 16:20
  • @ÇAĞATAYKAYA Don’t take it personal, that’s the best you can do. – ismail Jan 26 '19 at 16:22
-1

Open up windows calculator. Switch to programmer mode. Press DEC type in 1548445941. Notice how it shows HEX is 5C 4B 68 F5. Realise this is the value you got from registry but reversed, then read up about little endian.

Neil
  • 11,059
  • 3
  • 31
  • 56