In my code snippet, IShellLink was declared as a dual interface, although, after I have double checked it, it's only a IUnknown interface. Here is the right declaration and code :
[ComImport, Guid("00021401-0000-0000-C000-000000000046")]
class SH
{
}
[Guid("000214ee-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IShellLinkA // Cannot list any base interfaces here
{
// Note that IUnknown Interface members are NOT listed here:
void GetPath(string pszFile,
int cchMaxPath,
IntPtr pfd,
int fFlags);
void GetIDList(IntPtr ppidl);
void SetIDList(IntPtr pidl);
void GetDescription(string pszName,
int cchMaxName);
void SetDescription(string pszName);
void GetWorkingDirectory(string pszDir,
int cchMaxPath);
void SetWorkingDirectory(string pszDir);
void GetArguments(string pszArgs, int cchMaxPath);
void SetArguments(string pszArgs);
IntPtr GetHotkey();
void SetHotkey(int wHotkey);
void Resolve(IntPtr hwnd,
int fFlags);
void SetPath(string pszFile);
}
//
SH c = new SH();
IShellLinkA i = (IShellLinkA) c;
...
UCOMIPersistFile p = (UCOMIPersistFile) i;
p.Save(@"c:\mylink.lnk",false);