Click here to Skip to main content
15,890,690 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: LINK error1181:Cann't open input file "Gx.obj" Pin
kcynic6-Aug-07 11:53
kcynic6-Aug-07 11:53 
AnswerRe: LINK error1181:Cann't open input file "Gx.obj" Pin
Rage6-Aug-07 5:42
professionalRage6-Aug-07 5:42 
QuestionImage comparision Pin
Maynka6-Aug-07 4:03
Maynka6-Aug-07 4:03 
QuestionRe: Image comparision Pin
David Crow6-Aug-07 4:06
David Crow6-Aug-07 4:06 
Questionhiding a window below another control window Pin
prithaa6-Aug-07 3:48
prithaa6-Aug-07 3:48 
AnswerRe: hiding a window below another control window Pin
baerten6-Aug-07 4:07
baerten6-Aug-07 4:07 
AnswerRe: hiding a window below another control window Pin
KarstenK6-Aug-07 4:08
mveKarstenK6-Aug-07 4:08 
Questionenumerate the subkey in registry [modified] Pin
retinex6-Aug-07 3:43
retinex6-Aug-07 3:43 
I have written a piece of code to enumerate a subkey name in the registry.Here is the function:

<code>
HKEY RegOpen( HKEY hKey, LPCTSTR pszSubKey, DWORD dwRights)
{
	HKEY hSubKey;
	if ( RegOpenKeyEx(
			 hKey,
			 pszSubKey,
			 0,
			 dwRights,
			 &hSubKey
			 ) == ERROR_SUCCESS
	   )
	{
	    return hSubKey;
	}
	return NULL;
};
bool RegEnumSubKeys(
        CString szName, // subkey name 
        HKEY hStartKey, // the root key handle
        CString strStartKey // the root key path
        )
{
        DWORD dwSubKeyCnt, dwMaxSubKey;
        if ( RegQueryInfoKey(
                hStartKey,
                NULL,
                NULL,
                0,
                &dwSubKeyCnt,
                &dwMaxSubKey,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL
                ) == ERROR_SUCCESS
            )
        {
            if(dwSubKeyCnt)
            {
                dwMaxSubKey +=1; 
                LPTSTR pszKeyName = (LPTSTR)::malloc( dwMaxSubKey*sizeof(TCHAR) );
                if(pszKeyName)
                {
                    FILETIME ftWriteTime;
                    LONG retCode;
                    DWORD i=0;
                    for(i=0;i< dwSubKeyCnt; i++)
                    {
                        if (ERROR_SUCCESS == (retCode = RegEnumKeyEx(
                                hStartKey,
                                i,
                                pszKeyName,
                                &dwMaxSubKey,
                                NULL,
                                NULL,
                                NULL,
                                &ftWriteTime
                                ))
                            )
                        {
                            CString csFound;
                            csFound.Format(_T("%s\\%s"), strStartKey, pszKeyName);

                            TRACE(_T("%s\n"), csFound);
                            
                            HKEY hSubKey = RegOpen(hStartKey, pszKeyName, KEY_ALL_ACCESS);
                            if(hSubKey)
                            {
                                if(RegEnumSubKeys(szName, hSubKey, csFound))
                                {
                                    RegClose(hSubKey);                                    
                                }
                                else
                                {
                                    RegClose(hSubKey);
                                    ::free( (LPVOID) pszKeyName );
                                    return false;
                                }
                            }
                            else
                            {
                                ::free( (LPVOID) pszKeyName );
                                return false;
                            }
                        }                        
                        else
                        {
                            ::free( (LPVOID) (LPCTSTR) pszKeyName );
                            return false;
                        }
                    }
                    ::free( (LPVOID) pszKeyName );
                }
                else 
                    return false;                
            }
            return true;
        }
        return false;
};

unfortunately, the function only can trace one branch of the registry. I checked the code, the RegEnumKeyEx returned ERROR_MORE_DATA when it execute twice or more。However, if I use the RegEnumKey instead of RegEnumKeyEx, the function works well. Who can tell me why? Highly appreciated!






-- modified at 20:47 Monday 6th August, 2007
QuestionRe: enumerate the subkey in registry Pin
David Crow6-Aug-07 3:48
David Crow6-Aug-07 3:48 
AnswerRe: enumerate the subkey in registry Pin
retinex6-Aug-07 15:56
retinex6-Aug-07 15:56 
GeneralRe: enumerate the subkey in registry Pin
David Crow6-Aug-07 16:18
David Crow6-Aug-07 16:18 
GeneralRe: enumerate the subkey in registry Pin
retinex6-Aug-07 20:50
retinex6-Aug-07 20:50 
QuestionLegacy Code with VS 2005 Pin
Andy2026-Aug-07 3:28
Andy2026-Aug-07 3:28 
QuestionRe: Legacy Code with VS 2005 Pin
David Crow6-Aug-07 3:41
David Crow6-Aug-07 3:41 
AnswerRe: Legacy Code with VS 2005 Pin
Andy2026-Aug-07 4:43
Andy2026-Aug-07 4:43 
AnswerRe: Legacy Code with VS 2005 Pin
cp98766-Aug-07 13:58
cp98766-Aug-07 13:58 
QuestionHow to debug a shortcut to the application Pin
PravinSingh6-Aug-07 3:20
PravinSingh6-Aug-07 3:20 
AnswerRe: How to debug a shortcut to the application Pin
toxcct6-Aug-07 3:22
toxcct6-Aug-07 3:22 
GeneralRe: How to debug a shortcut to the application Pin
PravinSingh6-Aug-07 3:40
PravinSingh6-Aug-07 3:40 
QuestionConsole in MFC Pin
baerten6-Aug-07 2:43
baerten6-Aug-07 2:43 
QuestionRe: Console in MFC Pin
David Crow6-Aug-07 3:46
David Crow6-Aug-07 3:46 
AnswerRe: Console in MFC Pin
baerten6-Aug-07 4:05
baerten6-Aug-07 4:05 
QuestionHow To Obtain IP Adress of a Yahoo Messenger Chatter Pin
Pallab_GT6-Aug-07 2:41
Pallab_GT6-Aug-07 2:41 
AnswerRe: How To Obtain IP Adress of a Yahoo Messenger Chatter Pin
Nelek6-Aug-07 3:00
protectorNelek6-Aug-07 3:00 
GeneralRe: How To Obtain IP Adress of a Yahoo Messenger Chatter Pin
Hamid_RT6-Aug-07 8:59
Hamid_RT6-Aug-07 8:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.