consequence007
consequence007

Reputation: 2160

How to add UWP based hybrid application in the Windows Explorer's right click menu(contextmenu)?

We have developed a fulltrust file transfer app using UWP. It's basically a hybrid application using one of the Desktop bridge feature called Application Service. Now it's a requirement to add this application in the Window's file explorer right-click menu(contextmenu) like skype.

enter image description here

If we click on this menu, the application will be open with the file information that we can transfer based on the requirement.

What we have tried yet? Okay here below is the sample code we've tried.

<com:Extension Category="windows.comServer">
          <com:ComServer>
              <com:SurrogateServer AppId="d0c8bceb-28eb-49ae-bc68-454ae84d6264" DisplayName="My FT">
                  <com:Class Id="d0c8bceb-28eb-49ae-bc68-454ae84d6264" Path="ExplorerCommandVerb.dll" ThreadingModel="STA"/>
              </com:SurrogateServer>
          </com:ComServer>
    </com:Extension>
    <desktop4:Extension Category="windows.fileExplorerContextMenus" Executable="MyFT.exe" EntryPoint="App">
        <desktop4:FileExplorerContextMenus>
            <desktop4:ItemType Type="*">
                <desktop4:Verb Id="Command1" Clsid="d0c8bceb-28eb-49ae-bc68-454ae84d6264" />
            </desktop4:ItemType>
        </desktop4:FileExplorerContextMenus>
    </desktop4:Extension>
  </Extensions>

Where ExplorerCommandVerb.dll is COM based dll on IExplorerCommand. We have did some modification on ExplorerCommandVerb.dll. Like changed CLSID & Name like bellow:

void DllAddRef();
void DllRelease();

// use UUDIGEN.EXE to generate unique CLSID values for your objects

class __declspec(uuid("d0c8bceb-28eb-49ae-bc68-454ae84d6264")) CExplorerCommandVerb;
class __declspec(uuid("b3092d57-2ba5-469c-8110-1da4460b8d5b")) CExplorerCommandStateHandler;


static WCHAR const c_szVerbDisplayName[] = L"My FT";
static WCHAR const c_szVerbName[] = L"MyFT.ExplorerCommandStateHandlerVerb";
static WCHAR const c_szProgID[] = L"*";

HRESULT CExplorerCommandStateHandler_RegisterUnRegister(bool Register)
{
   HRESULT hr;
   if (Register)
   {
    // register a create process based verb. this could also be a delegate execute
    // or drop target verb
    CRegisterExtension registerCreateProcess(CLSID_NULL);
    hr = registerCreateProcess.RegisterCreateProcessVerb(c_szProgID, c_szVerbName, L"MyFT.exe %1", c_szVerbDisplayName);
    if (SUCCEEDED(hr))
    {
        hr = registerCreateProcess.RegisterVerbAttribute(c_szProgID, c_szVerbName, L"NeverDefault");
        if (SUCCEEDED(hr))
        {
            // now register the command state handler, this computes if this verb is enabled or not

            CRegisterExtension re(__uuidof(CExplorerCommandStateHandler));

            hr = re.RegisterInProcServer(c_szVerbDisplayName, L"Apartment");
            if (SUCCEEDED(hr))
            {
                hr = re.RegisterExplorerCommandStateHandler(c_szProgID, c_szVerbName);
            }
        }
    }
  }
  else
  {
    // best effort
    CRegisterExtension registerCreateProcess(CLSID_NULL);
    hr = registerCreateProcess.UnRegisterVerb(c_szProgID, c_szVerbName);

    CRegisterExtension re(__uuidof(CExplorerCommandStateHandler));
    hr = re.UnRegisterObject();
  }
  return hr;
}

Maybe we have done something wrong here that's why the context menu is not showing. Can anyone please let me know the details regarding the file explorer context menu add. Or is there any other way to do this?

As far as I know, the context menu can be added easily for desktop-based applications by adding some registry key and by specifying exe path in the registry path ("Computer\HKEY_CLASSES_ROOT\Directory\shell"). But there is no specific path for uwp app, windows somehow manage it on its own way.

As it's a file transfer app, right-click option should available for any files types.

We don't need to open with info by using "windows.fileTypeAssociation" as there is nothing to play or edit.

We need to workable "windows.fileExplorerContextMenus" this extension. I've searched for a long but found nothing workable. That's why I'm posting here for our honorable expert's opinion.

Here is the Microsoft doc link

Any kind of help will be appreciable. Thanks in advance.

N.B: Our application's minimum SDK support is 2004(20H2), so you can suggest any latest API if available.

Upvotes: 1

Views: 279

Answers (0)

Related Questions