8 messages in com.googlegroups.google-desktop-developerRe: Another C# Example
FromSent OnAttachments
Dan Forsyth10 Mar 2005 09:16 
Andy Babiec10 Mar 2005 09:28 
Tammy Wilcken10 Mar 2005 09:54 
Dan Forsyth10 Mar 2005 13:15 
Andy Babiec10 Mar 2005 15:11 
Andy Babiec10 Mar 2005 15:17 
Andy Babiec16 Mar 2005 10:11 
Aleks17 Mar 2005 00:37 
Subject:Re: Another C# Example
From:Andy Babiec (abab@gmail.com)
Date:03/10/2005 03:11:43 PM
List:com.googlegroups.google-desktop-developer

Here is what I did...

1. Created a strong name key... sn -k MyKeyFile.snk

2. Created a dll I could reference in my project tlbimp "c:\Program Files\Google\Google Desktop Search\GoogleDesktopAPI2.dll" /keyfile:MyKeyFile.snk /out:Interop.GoogleDesktopAPI2.dll /verbose

3. Created a solution with two c# projects: a DLL and an EXE The exe is used to initiate the register/unregister functionality in the DLL

4. Added references to the dll from step 2 above to the projects

5. Created a unique guid using genguid

6. Main class....

using System; using System.Runtime.InteropServices; using Microsoft.Win32; using System.Windows.Forms; using System.Diagnostics;

using Interop.GoogleDesktopAPI2;

namespace com.babiec.ZYXParserComponent { [Guid("D639C9A9-5863-45a3-B935-751808949F14"),ClassInterface(ClassInterfaceType.AutoDual)] public class ZYXParser : Interop.GoogleDesktopAPI2.DGoogleDesktopSearchFileNotify { const string kComponentGuid = "{D639C9A9-5863-45a3-B935-751808949F14}";

public ZYXParser() { // // TODO: Add constructor logic here // }

public bool RegisterWithGDS() { GoogleDesktopSearchRegisterClass gdsReg = new GoogleDesktopSearchRegisterClass(); string sExtension = "zyx"; try { // register/unregister the component

object [] componentDesc = new object[6] {"Title", sExtension + " Parser", "Description", "Parses " + sExtension + " Files", "Icon", "no icon"}; object reg = gdsReg.RegisterComponent(kComponentGuid, componentDesc);

SimpleMessageBox(sExtension + "Parser", "Registration completed successfully!", false);

try { IGoogleDesktopSearchComponentRegistration gdsCR = (IGoogleDesktopSearchComponentRegistration) reg;

gdsCR.RegisterExtension(sExtension ); SimpleMessageBox(sExtension + "Parser", sExtension + " Extension Registration completed successfully!", false); } catch (Exception e) { SimpleMessageBox("Registration Exception", e.ToString(), false); }

} catch(COMException e) { // check if not already registered if ((UInt32)e.ErrorCode != 0x80040006) // E_COMPONENT_ALREADY_REGISTERED { SimpleMessageBox("COM Exception", e.ToString(), false); return false; } else { SimpleMessageBox(sExtension + "Parser", "Component already registered - Unregistering!", false); gdsReg.UnregisterComponent(kComponentGuid);

} } catch (Exception e) { SimpleMessageBox("Exception", e.ToString(), false); return false; } finally {

} return true; }

private bool SimpleMessageBox(string caption, string text, bool okCancel) { DialogResult result = MessageBox.Show(text, caption, okCancel ? MessageBoxButtons.OKCancel : MessageBoxButtons.OK); return (result == DialogResult.OK) ? true : false; }

#region DGoogleDesktopSearchFileNotify Members

public void HandleFile(string full_path_to_file, object event_factory) { System.Diagnostics.EventLog.WriteEntry("ZYXParser", "entered HandleFile"); try {

// TODO: Add ZYXParser.HandleFile implementation IGoogleDesktopSearchEventFactory gdsEventFactory; IGoogleDesktopSearchEvent gdsEvent;

//object gdsEventDisp = gdsClass.CreateEvent(kComponentGuid, "Google.Desktop.IM"); //IGoogleDesktopSearchEvent gdsEvent = (IGoogleDesktopSearchEvent)gdsEventDisp;

gdsEventFactory = (IGoogleDesktopSearchEventFactory)event_factory; gdsEvent = (IGoogleDesktopSearchEvent) gdsEventFactory.CreateEvent(kComponentGuid, "Google.Desktop.TextFile"); gdsEvent.AddProperty("uri", full_path_to_file); gdsEvent.AddProperty("title", "test"); gdsEvent.AddProperty("format", "text/plain"); gdsEvent.AddProperty("last_modified_time", System.DateTime.Now.ToUniversalTime().ToOADate()); gdsEvent.AddProperty("content", "This is some sample ZYX content blah blah hope this works"); gdsEvent.Send(0x01); //SimpleMessageBox("ZYX Success", "ZYX Success", false); } catch (COMException e) { SimpleMessageBox("COM Exception", e.ToString(), false);

// protect some valid error results UInt32 error = (UInt32)e.ErrorCode; if (error != 0x80040005 && // E_COMPONENT_DISABLED error != 0x80040008 && // E_EVENT_TOO_LARGE error != 0x80040009 // E_SERVICE_NOT_RUNNING ) { SimpleMessageBox("COM Exception", e.ToString(), false); } } }

#endregion } }