0

I use shell namespace extension to create a virtual folder on windows 7. I want to add columns to this virtual folder so it can display the virtual files's details. However, the value for "Shared" cannot display correctly. Here is the related code:

else if (IsEqualPropertyKey(*pkey, PKEY_IsShared))
    {
        if (cch)
        {
            hr = StringCchCopy(pszRet, cch, L"");
        }
        else
        {
            pv->vt = VT_BOOL;

            BOOL isShared;
            GetIsShared(pidl, isShared);

            VARIANT_BOOL shared;

            if (isShared) shared = VARIANT_TRUE;//I add breakpoint here, it works
            else shared = VARIANT_FALSE;

            pv->pboolVal = &shared;

            hr = pv->pboolVal ? S_OK : E_OUTOFMEMORY;
        }
    }

Above code is located in the function IFACEMETHODIMP GetDetailsEx(PCUITEMID_CHILD pidl, const PROPERTYKEY *pkey, VARIANT *pv); which is a windows provided interface. enter image description here I add breakpoints to the above code, it turns out when the variable isShared is true, the variable shared does become VARIANT_TRUE. However, when I check the value it displays in the UI, it displays no for all objects: enter image description here As you can see, in the column of "Shared", all the value is "no". Actually, the top 3 files are shared and they should be "yes". when the debugger reaches the breakpoint in the above code, the value is VARIANT_TRUE for these three files. Here is the WINDOWS definition for PKEY_IsSahred

//  Name:     System.IsShared -- PKEY_IsShared
 //  Type:     Boolean -- VT_BOOL
//  FormatID: {EF884C5B-2BFE-41BB-AAE5-76EEDF4F9902}, 100
//
//  Is this item shared?  This only checks for ACLs that are not inherited.
DEFINE_PROPERTYKEY(PKEY_IsShared, 0xEF884C5B, 0x2BFE, 0x41BB, 0xAA, 0xE5, 0x76, 0xEE, 0xDF, 0x4F, 0x99, 0x02, 100);

I also tried to edit the above code like:

if (isShared) shared = (VARIANT_BOOL)1;
else shared = (VARIANT_BOOL)0;

It doesnw ork. If I replace pv->pboolVal = &shared; with pv->boolVal= shared;, it will work like: enter image description here Only display "Yes" for the top three files.

If I use VARIANT_TRUE and VARIANT_FALSE and pv->boolVal,it still only display "Yes".

pv->vt = VT_BOOL;

            BOOL isShared;
            GetIsShared(pidl, isShared);

            VARIANT_BOOL shared;

            if (isShared)
            {
                shared = VARIANT_TRUE;
                pv->boolVal = shared;
            }
            else
            {
                shared = VARIANT_FALSE;
                pv->boolVal= shared;
            }           

            hr = pv->boolVal ? S_OK : E_OUTOFMEMORY;

-----Working Update-------------------

if (isShared)
            {
                shared = VARIANT_TRUE;
                pv->boolVal = shared;
            }
            else
            {
                shared = VARIANT_FALSE;
                pv->boolVal = shared;
            }           

            hr = S_OK;

This one works for me!

beasone
  • 1,073
  • 1
  • 14
  • 32

1 Answers1

0

You should not use the pboolVal member here and assigning a pointer to something on the stack is certainly not the correct thing to do. The type would have to be VT_BYREF|VT_BOOL to use pboolVal but in this case there is no point to do that and you have no memory you can point to.

Just use boolVal and VARIANT_TRUE/FALSE.

Anders
  • 97,548
  • 12
  • 110
  • 164
  • Can you see my updates? When I use boolVal, it displays the second screenshot. ( Only display with "Yes") – beasone May 14 '18 at 16:19
  • `(VARIANT_BOOL)1` is wrong, use `VARIANT_TRUE`. Anyway, I assume it works correctly because Explorer in a normal folder will also sometimes display Yes, No and nothing ( https://imgur.com/a/dHK4TaL ). – Anders May 14 '18 at 16:29
  • If I use VARIANT_TRUE and VARIANT_FALSE and pv->boolVal,it still only display "Yes". – beasone May 14 '18 at 16:48
  • Are you returning S_OK even when it is not shared? – Anders May 14 '18 at 16:50
  • Oh, Thanks, that's the problem. When I return S_OK for both of them, it works ! – beasone May 14 '18 at 17:30