Createshortcut (maid, maid)
{
Hresult hres;
Ishelllink * PSL;
// Get a pointer to the ishelllink interface.
Hres = cocreateinstance (clsid_shelllink, null, clsctx_inproc_server,
Iid_ishelllink, (lpvoid *) & PSL );
If (succeeded (hres ))
{
Ipersistfile * PPF;
// Set the path to the specified cut target and add the description.
Psl-> setpath (lpszpathobj );
Psl-> setdescription (lpszdesc );
// Query ishelllink for the ipersistfile interface for saving
// Export cut 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 );
// Todo: Check return value from multibytewidechar to ensure
// 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.