[ComImport(),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
GuidAttribute("000214e4-0000-0000-c000-000000000046")]
public interface IContextMenu
{
// IContextMenu methods
[PreserveSig()]
int QueryContextMenu(uint hmenu, uint iMenu, int idCmdFirst, int idCmdLast, uint uFlags);
[PreserveSig()]
void InvokeCommand (IntPtr pici);
[PreserveSig()]
void GetCommandString(int idcmd, uint uflags, int reserved,
IntPtr commandstring, int cch);
}
private void MemCopy(IntPtr source, IntPtr dest, int cch)
{
byte[] buff = new byte[cch];
Marshal.Copy(source, buff, 0, cch);
Marshal.Copy(buff, 0, dest, cch);
}
private void WriteStringToPtrUnicode(IntPtr dest, string str, int cch)
{
IntPtr tempStrPtr = Marshal.StringToCoTaskMemUni(str);
MemCopy(tempStrPtr, dest, cch);
Marshal.FreeHGlobal(tempStrPtr);
}
public void GetCommandString(int idcmd, uint uflags, int reserved, IntPtr commandstring, int cch)
{
if (uflags == (uint)GCS.HELPTEXTW)
{
switch(idcmd)
{
case 0:
WriteStringToPtrUnicode(commandstring, "My help string", cch);
break;