Calling the WDS API from VB .NET

Some people in the Aqua-Soft forum had questions about how to call the Windows Desktop Search API from VB .NET.  There are two ways to do this right now, using our beta SDK.

1) Download the SDK and Sample (see my post below) files.  Reference WDSQuery.dll and include QueryBuilder.cs in your project.  Then you can instantiate a QueryBuilder object and use that (the comments in that file, or IntelliSense, will guide you).  It's pretty simple.

OR

2) Use the COM API directly. Here's what I posted over there:

Open VS 2003 and create a new VB.NET "Windows Forms" project. Add a reference to WDSQuery.dll.
Drop a DataGrid control from the toolbox onto the form, and size it reasonably. Leave the name as "DataGrid1" for now.
Copy and paste this code into the vb file:


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim mSearchClass As New Microsoft.Windows.DesktopSearch.Query.SearchDesktopClass
        Dim resultSet As Microsoft.Windows.DesktopSearch.Query._Recordset
        resultSet = mSearchClass.ExecuteQuery("test", "DocTitle,DocAuthor,Url", "DocTitle", Nothing)
        Dim DataSet1 As New System.Data.DataSet
        Dim DataTable1 As New System.Data.DataTable
        DataSet1.Tables.Add(DataTable1)
        Dim DataAdapter1 As New System.Data.OleDb.OleDbDataAdapter
        DataAdapter1.Fill(DataTable1, resultSet)
        DataGrid1.DataSource = DataSet1
        DataGrid1.DataMember = "Table1"
    End Sub


Build and run. Your datagrid should be filled with results for the query "test" - you can of course change that to something more pertinent to your index.

VB isn't really my thing, but that works on my system and should give you a basic idea of how to use the COM interfaces.

Option 1 is nice because QueryBuilder gives you easier query syntax to work with, and it gives you a decent list of Column Names that are supported in the current release (2.05) - remember, these are subject to change in future releases.

C# developers have a little easier time because they can read the sample code but not necessarily use it verbatim.  If you don't understand C# though it may not be as useful to you - it really depends on your usage. 

I'll be posting more about the SDK soon.  Tomorrow my cable gets installed at the new apartment, so I'll actually be able to lead the office and get more blogging done :)


Feedback

# re: Calling the WDS API from VB .NET

I tried to use this API but it is throwing ComException.

COM object with CLSID {1AD68C99-00FB-416D-804B-C38DEE75D55E} is either not valid or not registered.

I registered this dll using regasm tool too.
Can anyone help me with this? 8/9/2005 5:58 AM | Ruju

# re: Calling the WDS API from VB .NET

Do you have the most recent release of the MSN Search Toolbar with Windows Desktop Search installed? 8/9/2005 1:19 PM | Brandon Paddock

# re: Calling the WDS API from VB .NET

Ruju, try adding [STAThread] to your main, if it's not there already. I was getting exactly the same error until I added this attribute.

-------- ENTRY POINT ----
[STAThread]
static public void Main()
------------------------------ 9/24/2005 4:46 PM | Shawn

# re: Calling the WDS API from VB .NET

howo to call WDS APIS from C++?


Mary 10/24/2005 9:19 AM | Mary

# re: Calling the WDS API from VB .NET

Well it worked very good eaveb without the QueryBuilder.cs.
My question is , can i do the search on a remote machine ? 1/19/2006 2:31 AM | Avia

# re: Calling the WDS API from VB .NET

I can run WDS searches in my VB.NET program using your guidance, but what I really want to do is display the results via ASP.NET. If I try it, though, I get the following error at the point where I call the ExecuteQuery method:

>>>
Unable to cast COM object of type 'Microsoft.Windows.DesktopSearch.Query.SearchDesktopClass' to interface type 'Microsoft.Windows.DesktopSearch.Query.ISearchDesktop'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A227843C-1D92-48BC-AED6-DCA566F1790E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
<<<

Help!?!


2/19/2006 10:27 AM | cameron

# how can call a web page from a vb.net windows application

rtytry 1/31/2007 12:16 AM | sreejith

# re: Calling the WDS API from VB .NET

Hi

I would just like to call the Desktop Search programmatically from C#.NET so that it simply launches the Windows Desktop Search.

The code above doesn't seem to do that does it?

Any help would be great, thanks!

-Glenn 2/21/2007 3:17 AM | Glenn Pili

# re: Calling the WDS API from VB .NET

Nice site. You have many interesting discussion here. 4/27/2007 3:36 AM | autonowosci

# re: Calling the WDS API from VB .NET

Glenn Pili,

Hey! I just wanted to know if you are Glenn Pili from Philippines Angeles city. If you are please email me edu_911@yahoo.com. You have the same name as my high school friend. I've looking for you bro and I wish you are and we chat just like the old times. Sorry no VB question here just wanted to know. But I did take some java back in college. But if you are not Glenn Pili from the Philippines sorry to intrude in your coding discussion.

Mahalo
Norman 2/18/2008 8:50 AM | Norman Razon

Post a comment





 

Please add 7 and 8 and type the answer here:

News

The views expressed within my blog are my own - and are not in any way indicative of those of the company I work for, Microsoft, or it's employees.

Article Categories

Archives

Post Categories

Blogs I Read

Desktop Search Links

Syndication: