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
- //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
- }
- }
- Assemby file
- using System.Reflection;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- // General Information about an assembly is controlled through the following
- // set of attributes. Change these attribute values to modify the information
- // associated with an assembly.
- [assembly: AssemblyTitle("EventLib")]
- [assembly: AssemblyDescription("")]
- [assembly: AssemblyConfiguration("")]
- [assembly: AssemblyCompany("")]
- [assembly: AssemblyProduct("EventLib")]
- [assembly: AssemblyCopyright("Copyright © 2011")]
- [assembly: AssemblyTrademark("")]
- [assembly: AssemblyCulture("")]
- // Setting ComVisible to false makes the types in this assembly not visible
- // to COM components. If you need to access a type in this assembly from
- // COM, set the ComVisible attribute to true on that type.
- [assembly: ComVisible(true)]
- // The following GUID is for the ID of the typelib if this project is exposed to COM
- [assembly: Guid("4c80a921-5180-4b43-8b73-88cd93fa91f0")]
- // Version information for an assembly consists of the following four values:
- //
- // Major Version
- // Minor Version
- // Build Number
- // Revision
- //
- // You can specify all the values or you can default the Build and Revision Numbers
- // by using the '*' as shown below:
- // [assembly: AssemblyVersion("1.0.*")]
- [assembly: AssemblyVersion("1.0.*")]
- [assembly: AssemblyFileVersion("1.0.0.0")]
- FoxPro 9 testing code
- PUBLIC myObjt, loEvents
- myObjt = CREATEOBJECT("EventLib.EventTest")
- loEvents = CREATEOBJECT("EventsImp")
- ?EVENTHANDLER(myObjt,loEvents)
- DOEVENTS
- * callin activeX method to fire the event
- ?myObjt.GetEvent()
- *x=NEWOBJECT("myEvent")
- DEFINE CLASS EventsImp AS session
- IMPLEMENTS EventsImp IN "EventLib.EventTest"
- PROCEDURE EventsImp_SendMessage(message AS STRING) AS VOID
- ? message + " (From .net Event)"
- ENDPROC
- ENDDEFINE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement