Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Desktop Context menu "Paste Shortcut" issue, Please help

Desktop Context menu "Paste Shortcut" issue, Please help

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncement
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rahul Vaishnav
    wrote on last edited by
    #1

    Hi all, Please go through below function. Copy any file/folder & then use this function to past Shortcut It is crashing "InvokeCommand". Please help me.

    void PasteShortcut()
    {
    try
    {
    CoInitialize(NULL);
    IShellFolder* psf;
    HWND hWnd = GetDesktopWindow();
    HRESULT hr;
    if (SUCCEEDED(SHGetDesktopFolder(&psf)))
    {
    IContextMenu* pcm;
    if (SUCCEEDED(psf->CreateViewObject(hWnd,IID_IContextMenu,(void**)&pcm)))
    {
    HMENU hmenu = CreatePopupMenu();
    if (hmenu != NULL) {
    if (SUCCEEDED(pcm->QueryContextMenu(hmenu, 0,
    0, 0xff, // since we're invoking by canonical name the menu ID range passed to QueryContextMenu can be arbitrary
    CMF_NORMAL))) {
    CMINVOKECOMMANDINFO cmi={0};
    cmi.hwnd=hWnd;
    cmi.cbSize=sizeof(cmi);
    cmi.lpVerb= ".lnk";
    hr= pcm->InvokeCommand(&cmi);
    if (SUCCEEDED(hr)) {
    MessageBox(hWnd, TEXT("Shortcut created"), TEXT("Message"), 0);
    }
    }
    DestroyMenu(hmenu);
    }
    pcm->Release();
    }
    psf->Release();
    }
    CoUninitialize();

    }
    catch(...)
    {
    }
    

    }

    L 1 Reply Last reply
    0
    • R Rahul Vaishnav

      Hi all, Please go through below function. Copy any file/folder & then use this function to past Shortcut It is crashing "InvokeCommand". Please help me.

      void PasteShortcut()
      {
      try
      {
      CoInitialize(NULL);
      IShellFolder* psf;
      HWND hWnd = GetDesktopWindow();
      HRESULT hr;
      if (SUCCEEDED(SHGetDesktopFolder(&psf)))
      {
      IContextMenu* pcm;
      if (SUCCEEDED(psf->CreateViewObject(hWnd,IID_IContextMenu,(void**)&pcm)))
      {
      HMENU hmenu = CreatePopupMenu();
      if (hmenu != NULL) {
      if (SUCCEEDED(pcm->QueryContextMenu(hmenu, 0,
      0, 0xff, // since we're invoking by canonical name the menu ID range passed to QueryContextMenu can be arbitrary
      CMF_NORMAL))) {
      CMINVOKECOMMANDINFO cmi={0};
      cmi.hwnd=hWnd;
      cmi.cbSize=sizeof(cmi);
      cmi.lpVerb= ".lnk";
      hr= pcm->InvokeCommand(&cmi);
      if (SUCCEEDED(hr)) {
      MessageBox(hWnd, TEXT("Shortcut created"), TEXT("Message"), 0);
      }
      }
      DestroyMenu(hmenu);
      }
      pcm->Release();
      }
      psf->Release();
      }
      CoUninitialize();

      }
      catch(...)
      {
      }
      

      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It looks like the content of your CMINVOKECOMMANDINFO structure is not complete; take a look at the documentation[^] for further details.

      It's time for a new signature.

      R 1 Reply Last reply
      0
      • L Lost User

        It looks like the content of your CMINVOKECOMMANDINFO structure is not complete; take a look at the documentation[^] for further details.

        It's time for a new signature.

        R Offline
        R Offline
        Rahul Vaishnav
        wrote on last edited by
        #3

        Hi Richard, Thanks for reply... now I have tried below code... Below code is not showing crash as I have used "link" as lpVerb. as you said I have provided all Content of CMINVOKECOMMANDINFO structure. "InvokeCommand" is return S_OK But still Paste Shortcut is not happening on Desktop. :-(

        void PasteShortcut()
        {
        try
        {
        CoInitialize(NULL);

        	IShellFolder\* psf;
        	HWND hWnd = GetDesktopWindow();
        	HRESULT hr;
        	if (SUCCEEDED(SHGetDesktopFolder(&psf)))
        	{
        		IContextMenu\* pcm;
        		if (SUCCEEDED(psf->CreateViewObject(hWnd,IID\_IContextMenu,(void\*\*)&pcm)))
        		{
        			HMENU hmenu = CreatePopupMenu();
        			if (hmenu != NULL) {
        				if (SUCCEEDED(pcm->QueryContextMenu(hmenu, 0,
        					0 , 0xff,	// since we're invoking by canonical name the menu ID range passed to QueryContextMenu can be arbitrary
        					CMF\_NORMAL))) {
        						CMINVOKECOMMANDINFO  cmi;
        					cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
        					cmi.fMask = 0;
        					cmi.hwnd = hWnd;
        					cmi.lpVerb ="link" ;//(LPCSTR)(INT\_PTR)(idCmd - 1);
        					cmi.lpParameters = NULL;
        					cmi.lpDirectory = NULL;
        					cmi.nShow = SW\_NORMAL;
        					cmi.dwHotKey = 0;
        					cmi.hIcon = NULL;
        					hr = pcm->InvokeCommand(&cmi);
        						
        						if (SUCCEEDED(hr)) {
        							MessageBox(hWnd, TEXT("Shortcut created"), TEXT("Message"), 0);
        						}
        				}
        				DestroyMenu(hmenu);
        			}
        			pcm->Release();
        		}
        		psf->Release();
        	}
        	CoUninitialize();
        
        }
        catch(...)
        {
        }
        

        }

        L 1 Reply Last reply
        0
        • R Rahul Vaishnav

          Hi Richard, Thanks for reply... now I have tried below code... Below code is not showing crash as I have used "link" as lpVerb. as you said I have provided all Content of CMINVOKECOMMANDINFO structure. "InvokeCommand" is return S_OK But still Paste Shortcut is not happening on Desktop. :-(

          void PasteShortcut()
          {
          try
          {
          CoInitialize(NULL);

          	IShellFolder\* psf;
          	HWND hWnd = GetDesktopWindow();
          	HRESULT hr;
          	if (SUCCEEDED(SHGetDesktopFolder(&psf)))
          	{
          		IContextMenu\* pcm;
          		if (SUCCEEDED(psf->CreateViewObject(hWnd,IID\_IContextMenu,(void\*\*)&pcm)))
          		{
          			HMENU hmenu = CreatePopupMenu();
          			if (hmenu != NULL) {
          				if (SUCCEEDED(pcm->QueryContextMenu(hmenu, 0,
          					0 , 0xff,	// since we're invoking by canonical name the menu ID range passed to QueryContextMenu can be arbitrary
          					CMF\_NORMAL))) {
          						CMINVOKECOMMANDINFO  cmi;
          					cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
          					cmi.fMask = 0;
          					cmi.hwnd = hWnd;
          					cmi.lpVerb ="link" ;//(LPCSTR)(INT\_PTR)(idCmd - 1);
          					cmi.lpParameters = NULL;
          					cmi.lpDirectory = NULL;
          					cmi.nShow = SW\_NORMAL;
          					cmi.dwHotKey = 0;
          					cmi.hIcon = NULL;
          					hr = pcm->InvokeCommand(&cmi);
          						
          						if (SUCCEEDED(hr)) {
          							MessageBox(hWnd, TEXT("Shortcut created"), TEXT("Message"), 0);
          						}
          				}
          				DestroyMenu(hmenu);
          			}
          			pcm->Release();
          		}
          		psf->Release();
          	}
          	CoUninitialize();
          
          }
          catch(...)
          {
          }
          

          }

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Rahul Vaishnav wrote:

          But still Paste Shortcut is not happening on Desktop.

          I don't see anything in the above that looks like a source file or a destination shortcut.

          It's time for a new signature.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups