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

Threaded View

  1. #18
    Join Date
    Jul 2010
    Posts
    45

    Re: Working with registry

    Thanks again, now i tried to put your code into my and everything seems to be fine expect few little errors which i can't make right =(.

    Here is my whole code:

    Code:
    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #pragma comment(lib, "Advapi32.lib.")
    
    using namespace std;
    
    
    int main ()
    {
    	BOOL bGetBinary = FALSE;
    	HKEY hKey = NULL;
    	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), NULL, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
    	{
    		DWORD dwType = 0, dwBufferSize = 0;
    		if (!bGetBinary)
    		{
    			dwBufferSize = 260;
    			TCHAR tData[260];
    			if (RegQueryValueEx(hKey, TEXT("ProductName"), NULL, &dwType, (LPBYTE)&tData, &dwBufferSize) == ERROR_SUCCESS)
    			{
    				MessageBox(tData);
    			}
    			else
    				MessageBox(TEXT("Error!"));
    		}
    		else
    		{
    			dwBufferSize = 1024;
    			BYTE bBuffer[1024];
    			if (RegQueryValueEx(hKey, TEXT("ProductName"), NULL, &dwType, (LPBYTE)&bBuffer, &dwBufferSize) == ERROR_SUCCESS)
    			{
    				
    			}
    			else
    				MessageBox(TEXT("Error!"));
    
    		}
    
    	}

    I got errors here:

    Code:
    MessageBox(tData);
    1 IntelliSense: argument of type "TCHAR *" is incompatible with parameter of type "HWND"


    Code:
    MessageBox(TEXT("Error!"));
    3 IntelliSense: argument of type "const wchar_t *" is incompatible with parameter of type "HWND"

    Code:
    MessageBox(TEXT("Error!"));
    5 IntelliSense: argument of type "const wchar_t *" is incompatible with parameter of type "HWND"


    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    I got following error for all of this lines:
    2 IntelliSense: too few arguments in function call



    Also 1 more question, after program opens registry value how can I make the program write it's value on the screen? I tried cin << ProductName; but it won't work.

    PS. program worked after i erased those messagebox, as it was erased so were the errors.

    Code:
    dwBufferSize = 1024;
    			BYTE bBuffer[1024];
    			if (RegQueryValueEx(hKey, TEXT("ProductName"), NULL, &dwType, (LPBYTE)&bBuffer, &dwBufferSize) == ERROR_SUCCESS)
    			{
    				cout << ProductName;
    			}


    I'm really sorry for being such a pain in the *** but I really don't understand what went wrong now. =(

    Any conclusion?


    Thanks
    Last edited by harkoslav; July 22nd, 2010 at 10:24 AM.

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