Starting New Project C

Developing your first project in C#

  • Open Visual Studio.
  • Go to File > New > Project.
  • Select C# > Windows > Class Library.
  • Open your Project Properties panel.
  • Go to Build tab.
  • Check Register for COM interop.
  • Close Properties panel.
  • Right click References (in the Solution Explorer) and click Add Reference.
  • Go to COM tab.
  • Select:
    • Nektra NktWLMailApi library,
    • Nektra NktWLMailApiInit library,
    • Nektra NktWLMailApiStore library,
  • Click Ok.
  • WLMailApi loads the plugins installed in the Software\\Nektra\\WLMailApi\\Plugins Registry Key
Register DLL Plugin Example:

Register:

       static String pluginsKey = "Software\\Nektra\\WLMailApi\\Plugins";
       static String pluginValueName = "SimpleButtonDemo";
       // Here you have to put your Namespace.YourMain.cs
       static String pluginValueData = "SimpleButton.Plugin";
       // To load this DLL into WLMail, it must be added to WLMailApi's key in the registry 
       // and WLMail's agent must be running from startup.
       [ComRegisterFunctionAttribute]
       public static void RegisterFunction(Type t)
       {
           RegistryKey key = Registry.CurrentUser.OpenSubKey(pluginsKey, true);
           if (key == null)
           {   // key not found
               key = Registry.CurrentUser.CreateSubKey(pluginsKey);
               if (key == null)
               {
                   System.Windows.Forms.MessageBox.Show("Error registering component");
                   return;
               }
           }
           key.SetValue(pluginValueName, pluginValueData);
           key.Close();
       }

Unregister:

       [ComUnregisterFunctionAttribute]
       public static void UnregisterFunction(Type t)
       {
           RegistryKey key = Registry.CurrentUser.OpenSubKey(pluginsKey, true);
           if (key == null)
           {   // key not found
               return;
           }
           key.DeleteValue(pluginValueName, false);
           key.Close();
       }

  • A NktWLMailApiInit.WLMailApiInit and a NktWLMailApi.WLMailApi are also needed.
    • NktWLMailApiInit.WLMailApiInit will control Windows Live Mail Initialization events.
    • NktWLMailApi.WLMailApi is the core of the API.
Example Code with Core Initialization on Windows Live Mail Initialization, and proper Shutdown:

       // Declarations
       private NktWLMailApiInit.WLMailApiInit wlmailApiInit;
       private NktWLMailApi.WLMailApi wlmailApiCore;

// Class Start
       public Plugin()
       {
           wlmailApiInit = new NktWLMailApiInit.WLMailApiInitClass();
           wlmailApiInit.OnInit += new NktWLMailApiInit.IWLMailApiInitEvents_OnInitEventHandler(OnInitWLMailApi);
           wlmailApiInit.OnShutdown += new NktWLMailApiInit.IWLMailApiInitEvents_OnShutdownEventHandler(OnShutdownWLMailApi);
       }

       // Windows Live Mail Init Event Handler Function
       private void OnInitWLMailApi()
       {
           wlmailApiCore = new NktWLMailApi.WLMailApi();
       } 

// Windows Live Mail Shutdow Event Handler Function
       private void OnInitWLMailApi()
       {
           wlmailApiCore = null;
           wlmailApiInit.OnInit -= new NktWLMailApiInit.IWLMailApiInitEvents_OnInitEventHandler(OnInitWLMailApi);
           wlmailApiInit.OnShutdown -= new NktWLMailApiInit.IWLMailApiInitEvents_OnShutdownEventHandler(OnShutdownWLMailApi);
           // Call the Garbage Collector twice (only once is not enough)
           // or else Email Client will not shutdown
           GC.Collect();
           GC.WaitForPendingFinalizers();
           GC.Collect();
           GC.WaitForPendingFinalizers();
       }








Comments