+ Reply to Thread
Results 1 to 2 of 2

Thread: Create shortcut on desktop programmatically in C/C++.

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    24

    Create shortcut on desktop programmatically in C/C++.

    How can I create shortcut on desktop programmatically using WIN32/MFC in C/C++ based application? I want some simple function t do this.
    Please help.

  2. #2
    Following code can be useful to you:

    Code:
    void CreateDesktopShortcut(CString strLinkName, CString strPath)
    {
    	LPITEMIDLIST pItemList = NULL ;
    
    	HRESULT hResult = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pItemList) ;
    	if (SUCCEEDED(hResult))
    	{
    		char szPath[_MAX_PATH] ;
    		SHGetPathFromIDList(pItemList, szPath) ;
    		CComPtr<IShellLink> pShellLink = NULL ;
    		hResult = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &pShellLink) ;
    		if (SUCCEEDED(hResult))
    		{
    			CComPtr<IPersistFile> pPersistFile = NULL ;
    			pShellLink->SetPath(strPath) ;
    			hResult = pShellLink->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&pPersistFile));
    			if (SUCCEEDED(hResult))
    			{
    				USES_CONVERSION ;
    				strLinkName = CString(szPath) + "\\" + strLinkName + ".lnk" ;
    				hResult = pPersistFile->Save(A2W(strLinkName), TRUE);
    			}
    		}
    	}	
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts