Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ActiveX code
- using System;
- using System.Collections.Generic;
- //using System.Linq;
- using System.Text;
- using System.Data;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using Microsoft.Win32;
- using System.Windows.Forms;
- namespace EventLib
- {
- //[ComVisible(false)]
- //public delegate void eventDel (string message);
- //[GuidAttribute("93b89bc5-ad20-4e10-a02c-ff256b36dea8")]
- //[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
- [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
- public interface EventsImp
- {
- [DispId(1)] void SendMessage (string message);
- }
- //[Guid("d8f9f8d4-d395-49c6-97d7-ac319f12d085")]
- //[ProgId("EventLib.EventTest")]
- //[ClassInterface(ClassInterfaceType.AutoDual), ComSourceInterfaces(typeof(EventsImp))]
- [ComSourceInterfaces(typeof(EventsImp))]
- [ClassInterface(ClassInterfaceType.AutoDual)]
- [ProgId("EventLib.EventTest")]
- public class EventTest
- {
- public event eventDel testEvent;
- public delegate void eventDel (string message);
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public string GetEvent ()
- {
- try
- {
- // fire event;
- if (testEvent != null)
- {
- testEvent("Message from Event !");
- }
- return "Message not with event !";
- }
- catch (Exception ex)
- {
- return ex.Message;
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="message"></param>
- public void Testing (string message)
- {
- MessageBox.Show(message);
- }
- #region COM Registration
- //For more information on why the following two functions are necessary
- //http://www.codeproject.com/cs/miscctrl/exposingdotnetcontrols.asp
- //copyright Morgan Skinner, 2001
- [ComRegisterFunction()]
- public static void RegisterClass (string key)
- {
- // Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
- StringBuilder sb = new StringBuilder(key);
- sb.Replace(@"HKEY_CLASSES_ROOT\", "");
- // Open the CLSID\{guid} key for write access
- RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);
- // And create the 'Control' key - this allows it to show up in
- // the ActiveX control container
- RegistryKey ctrl = k.CreateSubKey("Control");
- ctrl.Close();
- // Next create the CodeBase entry - needed if not string named and GACced.
- RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
- inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
- inprocServer32.Close();
- // Finally close the main key
- k.Close();
- }
- [ComUnregisterFunction()]
- public static void UnregisterClass (string key)
- {
- StringBuilder sb = new StringBuilder(key);
- sb.Replace(@"HKEY_CLASSES_ROOT\", "");
- // Open HKCR\CLSID\{guid} for write access
- RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);
- // Delete the 'Control' key, but don't throw an exception if it does not exist
- k.DeleteSubKey("Control", false);
- // Next open up InprocServer32
- RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
- // And delete the CodeBase key, again not throwing if missing
- k.DeleteSubKey("CodeBase", false);
- // Finally close the main key
- k.Close();
- }
- #endregion
- }
- }
- FoxPro testing code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement