RegQueryValueEx ERROR

This is a discussion on RegQueryValueEx ERROR within the Windows Programming forums, part of the Platform Specific Boards category; I want to get the registry value (kind of char) and show to screen.. but I get "iiiiiiiiiiiiiiiiiiiiiiiii"... where is ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    44

    RegQueryValueEx ERROR

    I want to get the registry value (kind of char) and show to screen.. but I get "iiiiiiiiiiiiiiiiiiiiiiiii"... where is the problem???

    Code:
    HKEY hKey;
    	DWORD dwLen = sizeof(MAX_PATH);
        char dwKeyEn[MAX_PATH];
    	DWORD Type;
    	if (RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
    	RegQueryValueEx(HKEY_LOCAL_MACHINE,"Common Startup", NULL, &Type, (LPBYTE)dwKeyEn, &dwLen);
    	MessageBox(NULL, dwKeyEn, "UYARI", NULL);
    .....

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    I tried compiling your code with g++ on Linux but I got a bunch of errors.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    44
    ı use Microsoft Visual c++ 6.0 and ı didnt get error.. but ı get "iiiiiiiiiiiiiiiiiiiiiiiii"

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Moved to Windows programming forum.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by koyboy View Post
    ı use Microsoft Visual c++ 6.0 and ı didnt get error.. but ı get "iiiiiiiiiiiiiiiiiiiiiiiii"
    I was dropping a not-so-subtle hint that the thread should be moved...

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    44
    can anybody help to me??

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    What do the functions return? If they fail, they return an error.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Mixing your metaphors here:
    Code:
    DWORD dwLen = sizeof(MAX_PATH);
    That will give you a whopping 4 bytes to store your data in, so perhaps the error is that you need more space.

    Of course, if the data doesn't fit, then the OS will not fill any of it in [the principle is that if it doesn't fit, you check the length you got back, and make it so that you supply enough of a buffer when you kindly request it again]. What you quote as iiiiii is actualy character 208 (0xCC) [or is it 0xDD, 225 decimal, or some such?] that Windows fills local variables with so that you can detect when you use uninitialized memory easier.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    This works:
    Code:
    #include <stdio.h>
    #include <windows.h>
    
    int main(void)
    {
    	HKEY hKey;
    	DWORD dwLen = MAX_PATH;
    	char szKeyEn[MAX_PATH] = { 0 };
    	DWORD dwType = 0;
    	DWORD dwRetVal = 0;
    	if (ERROR_SUCCESS == (dwRetVal = RegOpenKeyEx(
    		HKEY_CURRENT_USER, 
    		"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", 
    		0, 
    		KEY_QUERY_VALUE, 
    		&hKey)))
    	{
                if (ERROR_SUCCESS == (dwRetVal = RegQueryValueEx(hKey, "Startup", 
    		NULL, &dwType, (LPBYTE)szKeyEn, &dwLen)))
    	   {
    		if (dwType == REG_EXPAND_SZ)
    		{
    		    char szStartupPath[MAX_PATH];
    		    if (0 != ExpandEnvironmentStrings(szKeyEn, szStartupPath, MAX_PATH))
    			printf ("Value is &#37;s\n", szStartupPath);
    		    else
    			printf ("Error expanding value: %ld\n", GetLastError());
    		}
    		else if (dwType == REG_SZ)
    		{
    		    printf ("Value is %s\n", szKeyEn);
    		}
    		else
    		{
    		    printf ("Unexpected type returned: %ld\n", dwType);
    		}
    	    }
    	    else
    	    {
    		printf ("Error querying value: %ld\n", dwRetVal);
    	    }
    
    	    RegCloseKey(hKey);
        }
        else
        {
    	printf ("Error opening key: %ld\n", dwRetVal);
        }
    
        return 0;
    }
    Last edited by rags_to_riches; 05-12-2008 at 01:03 PM. Reason: Goofed

  10. #10
    Registered User
    Join Date
    May 2008
    Posts
    44
    I changed it but I got "iiiiiiiiiiiiiii" again :S.. can you give another advice??

    Code:
    HKEY hKey;
    	DWORD dwLen = MAX_PATH;
        char dwKeyEn[MAX_PATH];
    	if (RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
    	RegQueryValueEx(HKEY_LOCAL_MACHINE,"Common Startup", 0, NULL, (LPBYTE)dwKeyEn, &dwLen);
    	MessageBox(NULL,dwKeyEn, "UYARI", NULL);

  11. #11
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    Although I provided the full answer above
    Code:
    RegQueryValueEx(HKEY_LOCAL_MACHINE,"Common Startup", 0, NULL, (LPBYTE)dwKeyEn, &dwLen);
    The first parameter to this function call needs to be the handle of the key you just opened; in your case, hKey:
    Code:
    RegQueryValueEx(hKey, "Common Startup", 0, NULL, (LPBYTE)dwKeyEn, &dwLen);

  12. #12
    Registered User
    Join Date
    May 2008
    Posts
    44
    that's wonderfull.. thanks @ rags_to_riches... I add this to my winapi app and changed printf to MessageBox and okkkkk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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