Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.InteropServices;
- using System.Runtime.InteropServices.ComTypes;
- namespace comtest
- {
- [ComVisible(true)]
- [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
- [Guid("9009311a-c0b2-42a4-8e7c-f42091d71594")]
- public interface ITestEvents {
- void OnEvent();
- }
- [ComVisible(true)]
- [ClassInterface(ClassInterfaceType.AutoDispatch)]
- [ComSourceInterfaces(typeof(ITestEvents))]
- public class ComClass {
- public event Action OnEvent;
- public int Test() {
- return 100;
- }
- }
- class Program
- {
- [DllImport("ole32.dll")]
- static extern int GetRunningObjectTable(uint reserved, out System.Runtime.InteropServices.ComTypes.IRunningObjectTable pprot);
- [DllImport("ole32.dll")]
- static extern int CreateFileMoniker([MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, out System.Runtime.InteropServices.ComTypes.IMoniker ppmk);
- public static void Main(string[] args)
- {
- IRunningObjectTable rot;
- IMoniker mon;
- var obj = new ComClass();
- GetRunningObjectTable(0, out rot);
- CreateFileMoniker("comTestApp", out mon);
- int ROTFLAGS_REGISTRATIONKEEPSALIVE = 1;
- rot.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, obj, mon);
- System.Threading.Thread.Sleep(3600000); // 1 hour
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement