Google 桌面外掛開發
外觀
| 華夏公益教科書使用者認為此頁面應該拆分為具有更窄子主題的較小頁面。 你可以透過將這個大頁面拆分成更小的頁面來提供幫助。請確保遵循命名策略。將書籍分成更小的部分可以提供更多重點,並允許每個部分都做好一件事,這對每個人都有益。 |
你需要建立一個 COM 物件。
GD 使用 COM 物件作為外掛。實際上,這些類似於 ActiveX 元件。它們旨在可重複使用。
在 Visual Studio 中,建立一個 C# 類庫。
你應該實現兩種(2)方法
static void ComRegisterFunctionAttribute(Type t) {
include initialization code here
}
每當你將 COM 物件註冊到系統時,都會呼叫此函式。你可以在這裡放置初始化程式碼,例如將我們的外掛註冊到 GD 的程式碼(稍後詳細介紹)。
static void ComUnregisterFunctionAttribute(Type t) {
}
每當你登出 COM 物件時,都會呼叫此函式。
你應該有以下語句
using System.Runtime.InteropServices;
構建類庫專案後,Visual Studio 會在你的輸出資料夾中生成以下檔案型別:.dll 和 .tlb
生成的 .dll 檔案實際上是一個 COM 物件,我們需要將其註冊到系統。
Use: regasm [dllfile] /tlb
Regasm.exe 位於你的 .Net Framework bin 資料夾中。
系統會呼叫 ComRegisterFunctionAttribute,因此你必須實現此方法。我們在這裡放置我們的初始化,例如將我們的外掛註冊到 GD 的程式碼塊。
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);
}
你的外掛將出現在 Google 桌面的新增/刪除面板列表中。
