public bool GetNewContextMenu(IListItemEx item, out IntPtr iContextMenuPtr, out IContextMenu iContextMenu) {
Guid CLSID_NewMenu = new Guid("{D969A300-E7FF-11d0-A93B-00A0C90F2719}");
Guid iicm = typeof(IContextMenu).GUID;
Guid iise = typeof(IShellExtInit).GUID;
if (Ole32.CoCreateInstance(
ref CLSID_NewMenu,
IntPtr.Zero,
Ole32.CLSCTX.INPROC_SERVER,
ref iicm,
out iContextMenuPtr) == (int)HResult.S_OK) {
iContextMenu = Marshal.GetObjectForIUnknown(iContextMenuPtr) as IContextMenu;
IntPtr iShellExtInitPtr;
if (Marshal.QueryInterface(
iContextMenuPtr,
ref iise,
out iShellExtInitPtr) == (int)HResult.S_OK) {
IShellExtInit iShellExtInit = Marshal.GetTypedObjectForIUnknown(
iShellExtInitPtr, typeof(IShellExtInit)) as IShellExtInit;
try {
iShellExtInit.Initialize(item.PIDL, null, 0);
Marshal.ReleaseComObject(iShellExtInit);
Marshal.Release(iShellExtInitPtr);
return true;
} finally {
}
} else {
if (iContextMenu != null) {
Marshal.ReleaseComObject(iContextMenu);
iContextMenu = null;
}
if (iContextMenuPtr != IntPtr.Zero) {
Marshal.ReleaseComObject(iContextMenuPtr);
iContextMenuPtr = IntPtr.Zero;
}
return false;
}
} else {
iContextMenuPtr = IntPtr.Zero;
iContextMenu = null;
return false;
}
}