Jump to content
Tom Wellige

Archive: SwyxIt Full-Text Search Plug-in in C#

Recommended Posts

The following blog post is restored from the Swyx Forum Archive (2007-2014) and was posted originally at 26.11.2008 in "Martin's Blog".


Before you continue you should read the first part about how to write a SwyxIt Plug-In in managed code. This blog post extends the first sample and adds full-text search support.

SwyxIt can ask a plug-in to find a number for a name, e.g. when you use the phonebook search function. A plug-in needs to support this custom COM interface which is defined in the SDK (CLMGgrPub.idl):



   helpstring("IFulltextSearchAddIn Interface"),
interface IFulltextSearchAddIn : IUnknown
   HRESULT FulltextSearchInContacts(
      [in] BSTR bstrSearchText, 
      [in] BOOL bEnableSearchInNumbers, 
      [in] IDispatch* pISearchResultCollection);        


In managed code this interface definition is


public interface IFulltextSearchAddIn
    [return: MarshalAs(UnmanagedType.Error)]
        int FulltextSearchInContacts(
        [MarshalAs(UnmanagedType.BStr), In()] string searchText,
        [MarshalAs(UnmanagedType.Bool), In()] bool enableSearchInNumbers,
        [MarshalAs(UnmanagedType.IDispatch), In(), Out()] object searchResultCollection);


The interface has some unusual semantics. The third parameter is an IDispatch based interface which is defined in CLMgrPub.idl like this:


    helpstring("INameNumberSearchResultCollection Interface"),
interface INameNumberSearchResultCollection : IDispatch
   [propget, restricted, id(DISPID_NEWENUM)] 
   HRESULT _NewEnum([out, retval] IUnknown** pVal);

    HRESULT Item([in] VARIANT index, [out, retval] VARIANT* pVariant);

   [propget, id(1)] 
   HRESULT Count([out, retval] long *pVal);

   [propget, id(2)] 
   HRESULT CreateItem([out, retval] IDispatch** ppVal);

   HRESULT AddItem([in] IDispatch* pVal);


It’s an input parameter, i.e. SwyxIt provides such a collection object to your plug-in. You just have to fill it with data.

As you can see from the definition INameNumberSearchResultCollection is an automation interface. We can just add a COM reference to clmgr.exe to our project in Visual Studio and the framework creates a runtime callable wrapper (RCW) for it. The items in this collection are NameNumberSearchResult objects. Fortunately the interface of that object is an automation interface too and the RCW has a definition of it, too.

Here’s a small sample implementation of the search function:


  1: public int FulltextSearchInContacts( 
  2:        string searchText, 
  3:        bool enableSearchInNumbers, 
  4:        object searchResultCollection)
  5: {
  6:     NameNumberSearchResultCollection resultCollection = (NameNumberSearchResultCollection)searchResultCollection;
  8:          // This is a sample, we find "Swyx" only. 
  9:          // Note: Swyxit always provides lower case text.
 10:          if (searchText.Contains("swyx"))
 11:     {
 12:         NameNumberSearchResult result = new NameNumberSearchResult();
 13:         result.Name = "Swyx Solutions AG (SampleAddIn result)";
 14:         result.Number = "+4923147770";
 15:         resultCollection.AddItem(result);
 16:     }
 18:         return 0;
 19: }


As you can see on line 6 the third parameter can be casted to a NameNumberSearchResultCollection. You just have to implement your search logic, create NameNumberSearchResult for each result and add it to the collection with AddItem() (lines 12 to 15).


Important: Per default full-text search is not enabled for SwyxIt! plug-ins. You have to create a REG_DWORD registry value named


and set it to 1. It’s located in the registry key of your plug-in (See the previous blog entry). Without that registry value SwyxIt does not use the plug-in’s IFullTextSearchAddIn interface.


Last, but not least, here’s the updated sample plugin from the previous post. Have fun.





Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.