Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3224058
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:10:43+00:00 2026-05-17T16:10:43+00:00

I need to programmatically create a shortcut using C++. How can I do this

  • 0

I need to programmatically create a shortcut using C++.

How can I do this using Win32 SDK?

What API function can be used for this purpose?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:10:44+00:00Added an answer on May 17, 2026 at 4:10 pm

    Try Windows Shell Links. This page also contains a C++ example. Descriptive Snippet:

    Using Shell Links

    This section contains examples that
    demonstrate how to create and resolve
    shortcuts from within a Win32-based
    application. This section assumes you
    are familiar with Win32, C++, and OLE
    COM programming.

    EDIT: Adding the code sample in case the link dies (and MSDN links do die often.)

    // CreateLink - Uses the Shell's IShellLink and IPersistFile interfaces 
    //              to create and store a shortcut to the specified object. 
    //
    // Returns the result of calling the member functions of the interfaces. 
    //
    // Parameters:
    // lpszPathObj  - Address of a buffer that contains the path of the object,
    //                including the file name.
    // lpszPathLink - Address of a buffer that contains the path where the 
    //                Shell link is to be stored, including the file name.
    // lpszDesc     - Address of a buffer that contains a description of the 
    //                Shell link, stored in the Comment field of the link
    //                properties.
    
    #include "stdafx.h"
    #include "windows.h"
    #include "winnls.h"
    #include "shobjidl.h"
    #include "objbase.h"
    #include "objidl.h"
    #include "shlguid.h"
    
    HRESULT CreateLink(LPCWSTR lpszPathObj, LPCSTR lpszPathLink, LPCWSTR lpszDesc) 
    { 
        HRESULT hres; 
        IShellLink* psl; 
    
        // Get a pointer to the IShellLink interface. It is assumed that CoInitialize
        // has already been called.
        hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); 
        if (SUCCEEDED(hres)) 
        { 
            IPersistFile* ppf; 
    
            // Set the path to the shortcut target and add the description. 
            psl->SetPath(lpszPathObj); 
            psl->SetDescription(lpszDesc); 
    
            // Query IShellLink for the IPersistFile interface, used for saving the 
            // shortcut in persistent storage. 
            hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); 
    
            if (SUCCEEDED(hres)) 
            { 
                WCHAR wsz[MAX_PATH]; 
    
                // Ensure that the string is Unicode. 
                MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH); 
    
                // Save the link by calling IPersistFile::Save. 
                hres = ppf->Save(wsz, TRUE); 
                ppf->Release(); 
            } 
            psl->Release(); 
        } 
        return hres; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a Firebird Database programmatically using DBExpress. I have done this
I need to programmatically enable READ COMMITTED SNAPSHOT in SQL Server. How can I
I would like to create a shortcut on the desktop using VBScript code. I
I have some code that is used to programmatically create a Document to send
My current program need to use programatically create a XPathExpression instance to apply to
I need to programmatically solve a system of linear equations in C, Objective C,
I need to programmatically determine out how many sectors, heads, and cylinders are on
I have a C code base and need to programmatically identify all of the
I am creating a C# Windows Mobile application that I need to programmatically invoke
I have a database full of small HTML documents and I need to programmatically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.