VC creation shortcut

xiaoxiao2021-03-06  39

Createshortcut (LPCSTR LPSZPATHLINK, LPCSTR LPSZPATHOBJ, LPCSTR LPSZDESC)

{

HRESULT HRES;

IshellLink * PSL;

// Get a pointer to the ishelllink interface.

HRES = CocreateInstance (CLSID_SHELLLINK, NULL, CLSCTX_INPROC_SERVER,

IID_ID_IDLLINK, (LPVOID *) & PSL);

"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, (LPVOID *) & PPF);

"succeeded (hres))

{

Wchar WSZ [MAX_PATH];

// EnSure That the string is uncode.

MultibyToWideChar (CP_ACP, 0, LPSZPATHLINK, -1, WSZ, MAX_PATH);

// Todo: Check Return Value from MultibyTewideChar To Enssure

// Save the link by calling ipersistfile :: save.

HRES = PPF-> Save (WSZ, TRUE);

PPF-> Release ();

}

PSL-> Release ();

}

Return HRES;

}

Don't forget to call Coinitialize (NULL) first.

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

New Post(0)