0% developed

Plug-in Development for Google Desktop

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Getting Started[edit | edit source]

Things you need[edit | edit source]

How to get started[edit | edit source]

You need to create a COM object.

What is a COM object and why do I need to create it?[edit | edit source]

GD uses COM objects as plugins. Actually these are like ActiveX components. They are meant to be reusable.

How to create a COM object[edit | edit source]

In Visual Studio, create a C# Class Library.

Preliminary code for the Class Library project[edit | edit source]

You should implement two (2) methods:

static void ComRegisterFunctionAttribute(Type t) {
include initialization code here
}

This function is called whenever you register your COM object to the system. You can put initialization code here, like code that will register our plugin to GD (Details later).

static void ComUnregisterFunctionAttribute(Type t) {
}

This function is called whenever you unregister your COM object.

You should have the following statement:

using System.Runtime.InteropServices;

What kind of files are created when I compile my Class Library project?[edit | edit source]

After building your Class Library project, Visual Studio will generate the following file types in your output folder: .dll and .tlb

The .dll file generated is actually a COM object that we need to register to the system.

How to load/register a COM object[edit | edit source]

Use: regasm [dllfile] /tlb

Regasm.exe is located in your .Net Framework bin folder.

What method/code is first executed after I load a COM object?[edit | edit source]

The system makes a call to ComRegisterFunctionAttribute so it is necessary that you implement this method. It is here where we put our initialization, like a block of code that will register our plugin to GD.

Registering the plugin to GD[edit | edit source]

try {
GoogleDesktopRegistrarClass registrar = new GoogleDesktopRegistrarClass();
// Start component registration by specifying our attributes
object[] descriptions = {
"Title", pluginName,
"Description", pluginName,
"Icon", ""
};

registrar.StartComponentRegistration(controlGuid, descriptions);

IGoogleDesktopRegisterDisplayPlugin displayRegistration = 
(IGoogleDesktopRegisterDisplayPlugin)

registrar.GetRegistrationInterface("GoogleDesktop.DisplayPluginRegistration");

displayRegistration.RegisterPlugin(controlGuid, false);
// Done with component registration.
registrar.FinishComponentRegistration();
}
catch (Exception e) {
MessageBox.Show("Exception thrown during registration. Description=" + e.Message);
}

What happens when my plugin is registered in GD?[edit | edit source]

Your plugin will appear in the add/remove panel list in Google Desktop.

Advanced Topics[edit | edit source]

Clipboard

To do: