RE: CreateMutex fails with ERROR_UNKNOWN_REVISION

From: SpaCat (anonymous_at_discussions.microsoft.com)
Date: 04/23/04


Date: Thu, 22 Apr 2004 15:36:02 -0700

By the way, i found out something interesting. I didn't mention it before, but since my program has to work both with Windows 9x and Windows NT based, i couldn't link directly to sddl.h - i had to LoadLibrary/GetProcAddress it.
Surprisingly enough, when i return to the original code (the way you described), i don't get this strange error. Only when i use the LoadLibrary method i'm getting it.
It looks something like this:

typedef BOOL (WINAPI *CONVERTSTRSECDESCTOSECDESC)(LPCSTR, DWORD, PSECURITY_DESCRIPTOR*, PULONG);

BOOL DelayConvertStringSecurityDescriptorToSecurityDescriptor(LPCSTR StringSecurityDescriptor,
                                        DWORD StringSDRevision,
                                        PSECURITY_DESCRIPTOR* SecurityDescriptor,
                                        PULONG SecurityDescriptorSize)
{
        static BOOL bInit = FALSE;
        BOOL bResult = FALSE;
        TCHAR tcSysPath[MAX_PATH];

        if(GetSystemDirectory(tcSysPath, sizeof(tcSysPath)))
                strncat(tcSysPath, "\\AdvAPI32.dll", 14);
        
        if (!bInit)
        {
                hMod = LoadLibrary(tcSysPath);
                bInit = TRUE;
        }
        if (hMod)
        {
                CONVERTSTRSECDESCTOSECDESC pfnConvertStringSecurityDescriptorToSecurityDescriptor = NULL;
                pfnConvertStringSecurityDescriptorToSecurityDescriptor = (CONVERTSTRSECDESCTOSECDESC) GetProcAddress(hMod, "ConvertStringSecurityDescriptorToSecurityDescriptorA");
                if (pfnConvertStringSecurityDescriptorToSecurityDescriptor)
                {
                        return ((pfnConvertStringSecurityDescriptorToSecurityDescriptor)(StringSecurityDescriptor,
                                                StringSDRevision,
                                                SecurityDescriptor,
                                                SecurityDescriptorSize));
                }
                else
                {
                        DWORD dwError = GetLastError();
                        dprintf ("pfnConvert failed = error is [%d]\n", dwError);
                }
        }
        else
        {
                DWORD dwError = GetLastError();
                dprintf ("hMod failed = error is [%d]\n", dwError);
        }

        return 0;
}

And i call it like this:

        if(DelayConvertStringSecurityDescriptorToSecurityDescriptor(
                                szSDDLString,
                                SDDL_REVISION_1,
                                &sa.lpSecurityDescriptor,
                                NULL))
        {
                dprintf("Delay returned true\n");
        }
        else
        {
                dprintf("Delay returned false\n");
        }

        if (hMod) // Free the AdvApi32 dll
                FreeLibrary(hMod);

         // Free the memory allocated for the SECURITY_DESCRIPTOR.
        if (NULL != LocalFree(sa.lpSecurityDescriptor))
        {
                dprintf("Failed LocalFree\n");
        }

Does this makes sense?



Relevant Pages

  • Re: Can Windows XP do this? (backup)
    ... BOOL Hibernate, ... BOOL DisableWakeEvent ... Windows NT/2000/XP: Included in Windows 2000 and later. ...
    (microsoft.public.windowsxp.general)
  • How to detect whether terminal services is installed in Windows XP Pro
    ... These code is used to detect whether terminal services is installed in windows. ... However, when I run these code in windowsXP Pro, the result is the terminal services isn't install. ... BOOL AreWeRunningTerminalServices ...
    (microsoft.public.win2000.termserv.apps)
  • Re: Cisco Aironet 350 & CE.NET 4.2
    ... SYSINTR seems ok, I/O seems ok, 4.1 works ok, 4.2 doesn't. ... >> Michel Verhagen, eMVP ... >> Windows CE Consultant ... >> BOOL ...
    (microsoft.public.windowsce.platbuilder)
  • Re: bool or BOOL in MFC projects
    ... which failed under Windows 95 because the API returned a non-zero ... In fact, correct me if I am wrong, expressions comparing integers a<b a==b return an integer 1 or 0 don't they? ... My 1991 copy of Stroustrup predates "bool", and so I am never sure about things like this :-) They haven't changed it have they? ... If not, the BOOL concept appears implicit in the language, even if it is Windows which actually defines the type BOOL. ...
    (microsoft.public.vc.mfc)