Thread: RegQueryValueEx ERROR

  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
    28,413
    Moved to Windows programming forum.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    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
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    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, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM