VC learning materials collection (23): Create shortcuts

xiaoxiao2021-03-06  41

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;}

转载请注明原文地址:https://www.9cbs.com/read-71767.html

New Post(0)