Thread: RegCreateKey() ?

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    7

    Unhappy RegCreateKey() ?

    Win32,i write the RegCreateKeyEx() function like this, it's working

    HKEY hkey;
    DWORD dwDisposition=0;
    RegCreateKeyEx(HKEY_CLASSES_ROOT,"NewApp",0,"",REG _OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,
    &hkey,&dwDisposition);


    MFC, i write the RegCreateKeyEx() function like below, no error but just can't create a key in registry, why?

    HKEY hkey;
    DWORD dwDisposition=0;
    ::RegCreateKeyEx(HKEY_CLASSES_ROOT,"NewApp",0,"",R EG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,
    &hkey,&dwDisposition);


    in addtion, what is the different beyween these two statement in MFC
    RegCreateKeyEx(...);
    ::RegCreateKeyEx(...);
    Last edited by mkyong; 02-02-2003 at 08:32 PM.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    What value is RegCreateKeyEx() returning? If the call works, it returns ERROR_SUCCESS, (defined in winerror.h), otherwise it returns another value from the same header.

    I don't use MFC, but in this context, (MFC), I believe using the scope resolution operator, (::), tells the compiler you want to use the standard API function rather than any member function of a class. That being the case, the two calls should be the same.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Indeed :: indicates that you are taking a function from the global scope. And your call to RegCreateKeyEx() looks good enough. But just for the hell of it why not try

    Code:
     HKEY hkey;
    SECURITY_ATTRIBUTES sAttribs = {sizeof(SECURITY_ATTRIBUTES)};
    DWORD dwDisposition=0;
    RegCreateKeyEx(HKEY_CLASSES_ROOT,"NewApp",0,"",REG_OPTION_VOLATILE,KEY_ALL_ACCESS, &sAttribs, &hkey,&dwDisposition);

Popular pages Recent additions subscribe to a feed