CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 33

Threaded View

  1. #20
    Join Date
    Jul 2010
    Location
    Mexico
    Posts
    21

    Re: Working with registry

    Sorry, i forgot the HWND parameter, i wrote that code on an MFC app so it just needed the string parameter (as Dadidum said).

    To get the code working just change:

    Code:
    MessageBox(tData);
    MessageBox(TEXT("Error!"));
    to

    Code:
    MessageBox(NULL, tData);
    MessageBox(NULL, TEXT("Error!"));
    The NULL instead of a window handle (HWND-type parameter, a long-type value) is because MessageBox requires an owner window, and since you don't have any, you can pass a NULL value. Modify the other MessageBox'es and you're done.

    If you want to display the value on the screen by using std::cout then you should use the buffer where the values are stored, in this case, the tData variable of the first RegQueryValue:

    Code:
    dwBufferSize = 260;
    TCHAR tData[260];
    if (RegQueryValueEx(hKey, TEXT("ProductName"), NULL, &dwType, (LPBYTE)&tData, &dwBufferSize) == ERROR_SUCCESS)
    {
    	wcout << tData;
    }
    else
    	wcout << TEXT("Error!");
    The second RegQueryValue gets the raw binary data from the registry in a BYTE array (BYTE equals to unsigned char for windows) and i only included that because you said you wanted to get some binary data, but the info we're getting from the registry in this example is a REG_SZ so the first options is a better choice since it gets the string directly. Play with the code, and again, check the msdn docs (you may use your VS help or try at www.msdn.com) because windows uses a lot of strange data types that you should know about, if you have more questions, please let us know.

    And another advice: i used wcout instead of cout because your'e using Unicode, the 'w' before some functions means that it is the 'wide-char' version of the function. Check this post for more advice on cout and wcout http://www.codeguru.com/forum/showthread.php?t=500451

    And don't worry, this forum was made to allow us to share our knowledge with others, sometimes we need a little help, sometimes we can give a little help :-)
    Last edited by bioHzrdmX; July 22nd, 2010 at 09:59 AM.
    "A program is never less than 90% complete, and never more than 95% complete."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured