Wednesday, July 30, 2008

Google Desktop Actions

To implement Custom Actions and integrate your application with Google Desktop you will need, in addition to the information in this document:
* Sufficient access to write a plug-in for your application and an installer for it.
* Programming knowledge of the Microsoft Windows Component Object Model (COM).
The Action API consists of a COM interface, which must be exposed by plug-ins wishing to implement custom actions.


  1. [ComVisible(true)]
  2. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  3. [GuidAttribute("E5A04D23-6921-4ef6-B19B-6C6AA89A46AA")]
  4. public interface IGoogleDesktopCustomAction
  5. {
  6.   [DispId(1)]
  7.   void QueryInterest(
  8.     [In] Guid location,
  9.     [In] Guid action,
  10.     [In, MarshalAs(UnmanagedType.BStr)] string query_string,
  11.     [In, MarshalAs(UnmanagedType.IUnknown)] object item,
  12.     [In, Out, MarshalAs(UnmanagedType.BStr)] ref string actionTitle,
  13.     [Out, MarshalAs(UnmanagedType.BStr)] out string actionCookie,
  14.     [Out] out ActionHandling handling);
  15.  
  16.   [DispId(2)]
  17.   void HandleAction(
  18.     [In] Guid location,
  19.     [In] Guid action,
  20.     [In, MarshalAs(UnmanagedType.BStr)] string query_string,
  21.     [In, MarshalAs(UnmanagedType.IUnknown)] object item,
  22.     [In, MarshalAs(UnmanagedType.BStr)] string action_cookie);
  23. }
* This source code was highlighted with Source Code Highlighter.


The following sample demonstrates how a component can implement the methods on the IGoogleDesktopCustomAction interface.
QueryInterest is invoked when search results are displayed in browser and HandleAction is invoked when you are opening specific item of search result.


  1. [ComVisible(true)]
  2. [GuidAttribute("YOU-GUID")]
  3. public class SearchActions : IGoogleDesktopCustomAction
  4. {
  5.   #region IGoogleDesktopCustomAction Members
  6.  
  7.   public void HandleAction(
  8.     Guid location, Guid action, string query, object item, string actionCookie)
  9.   {
  10.     try
  11.     {
  12.       string uri = ((IGoogleDesktopNotifyEvent)item).GetProperty("uri").ToString();
  13.       System.Diagnostics.Process.Start(uri);
  14.     }
  15.     catch (COMException ex)
  16.     { }
  17.   }
  18.  
  19.   public void QueryInterest(
  20.     Guid location, Guid action, string query, object item,
  21.     ref string actionTitle, out string actionCookie, out ActionHandling handling)
  22.   {
  23.     string extension = uri.Substring(uri.LastIndexOf('.') + 1);
  24.     if (extension == "txt")
  25.       handling = ActionHandling.ACTION_HANDLING_OVERRIDE;
  26.     else
  27.       handling = ActionHandling.ACTION_HANDLING_DEFAULT;
  28.   }
  29. }
* This source code was highlighted with Source Code Highlighter.

1 comment:

  1. Could you attach a complete (but simple) example of Google Desktop Actions workin in c# or vb.net?
    I have managed to register with GoogleDesktop.ActionRegistration (and at the same time register in Query API and Index API, services that I have used successfully).
    However, I have created a COM Class to implement IGoogleDesktopCustomAction, in c#, in the way you show, and nothing: the methods QueryInterest or HandleAction are never called.
    I have tried changing "void QueryInterest(.." to "int QueryInterest(..."; I have tried with vb.net, etc, but nothing.

    Thanks
    Daniel

    ReplyDelete