Create Shortcut
2004-5-12 0:15:49 Read 24 times to create a shortcut HRESULT CreateLink (LPCSTR lpszPathObj, LPSTR lpszPathLink, LPSTR lpszDesc) {HRESULT hres; IShellLink * psl; CoInitialize (NULL); // Get a pointer to the IShellLink interface . hres = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) & 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 for saving the // shortcut in persistent storage hres = psl-> QueryInterface (IID_IPersistFile, (void **) & ppf);. IF (succeeded (hres)) {Word WSZ [MAX_PATH]; // EnSure That The string is ANSI. 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;}