From: http://www.vckbase.com
ReadingCodeBefore that, let's take a look at the structure of the "shortcut" component.
Figure 2 interface structure of the shortcut component
From the structure diagram, we can see that the "shortcut" component (clsid_shelllink) has three (in fact, more than one) interfaces, each of which completes a set of functions. The ishelllink interface (iid_ishelllink) provides a shortcut for parameter read/write (see figure 3). The ipersistfile interface (iid_ipersistfile) provides a shortcut for persistent file read/write. Object persistence (note 5) is a very common and powerful interface family. But today, we only need to know two of these functions: ipersistfile: Save () and ipersistfile: load (). (Note 6)
Figure 3. Attributes of shortcuts
# Include <atlconv. h> void createshortcut (lpctstr lpszexe, lpctstr lpszlnk) {// create a blockchain method // parameter lpszexe: full path name of the EXE file // parameter lpszlnk: full path name of the shortcut file :: coinitialize (null); ishelllink * PSL = NULL; ipersistfile * PPF = NULL; hresult hR =: cocreateinstance (// start component clsid_shelllink, // shortcut clsidnull, // for aggregation (note 4) clsctx_inproc_server, // The iid_ishelllink and the iid (lpvoid *) of the shell32.dll service in the process. & PSL ); // obtain the interface pointer if (succeeded (HR) {PSL-> setpath (lpszexe); // full path Program Name // PSL-> setarguments (); // command line parameter // PSL-> setdescription (); // remarks // PSL-> sethotkey (); // shortcut // PSL-> seticonlocation (); // icon // PSL-> setshowcmd (); // window size // according to the EXE file name, obtain the directory name tchar szworkpath [max_path];: lstrcpy (szworkpath, lpszexe); lptstr Lp = szworkpath; while (* LP) LP ++; while (''//''! = * LP) LP --; * Lp = 0; // set the default working directory of the EXE program, PSL-> setworkingdirectory (szworkpath ); hR = PSL-> QueryInterface (// persistence file query interface pointer iid_ipersistfile, // persistence interface IID (lpvoid *) & PPF ); // obtain the interface pointer if (succeeded (HR) {uses_conversion; // convert it to the Unicode string PPF-> Save (t2cole (lpszlnk), true ); // save} If (PPF) PPF-> release (); If (PSL) PSL-> release ();: couninitialize ();} void onxxx () {createshortcut (_ T ("C: // winnt // notepad.exe "), // Notepad program. Note: Is your system also in this directory? _ T ("C: // Documents and Settings // administrator // desktop // my notepad. lnk "); // create the full path name of the shortcut (lnk) file on the desktop. Note: Is your system also in this directory? // If you use a program to find the desktop path, you can check the registry // HKEY_CURRENT_USER/software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders}