oo. nice code. I need to learn a bit about what the features of com do, but I just dumped it in the ide to play with.
Thanks, Tyler Littlefield email: tyler@xxxxxxxxxxxxx web: tysdomain-com Visit for quality software and web design. skype: st8amnd2005----- Original Message ----- From: "Macarty, Jay {PBSG}" <Jay.Macarty@xxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx> Sent: Friday, November 14, 2008 2:05 AM Subject: RE: C# and COM - creating COM events Sample C# code is as follows: using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace QuoteQuad { public delegate void EventDel(int val); [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] public interface UserEvents { [DispId(5)] void MyEvent(int val); } [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface _Demo { [DispId(1)] int MyMethod(int numarg); [DispId(2)] string MMethod(); [DispId(3)] int MyProperty { get; set;} [DispId(4)] void eventm(int val); } [ClassInterface(ClassInterfaceType.None)] [ProgId("QuoteQuad.Demo")] [ComSourceInterfaces(typeof(UserEvents))] public class Demo : _Demo { public event EventDel MyEvent; public Demo() { } private int myVar; public int MyProperty { get { return myVar; } set { MyEvent(value); myVar = value; } } public int MyMethod(int numarg) { return numarg + 10; } public string MMethod() { return "Jay Macarty"; } public void eventm(int val) { MyEvent(7); } } } And the Assembly.cs looks like this: 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("QuoteQuad")] [assembly: AssemblyDescription("C# COM Interrop DLL: Step-by-step guide")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("QuoteQuad")] [assembly: AssemblyCopyright("Copyright (c) 2006")] [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("49a5c035-e8c5-46b0-8317-499b7bc5e511")]// 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 Revision and Build Numbers
// by using the '*' as shown below: [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]After you compile this and register it using regasm, You can run the following VBScript which uses the COM object:
set obj = WScript.CreateObject("QuoteQuad.Demo", "dm_") MsgBox "Value from MyMethod is " & obj.MyMethod(10) obj.MyProperty = 5 Sub dm_MyEvent(name) MsgBox "Event fired - name is " & name End Sub -----Original Message-----From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of E.J. Zufelt
Sent: Tuesday, November 11, 2008 2:04 PM To: programmingblind@xxxxxxxxxxxxx Subject: Re: C# and COM - creating COM events Good afternoon, If it's possible, Could you share your sample code with the list? Thanks, Everett ----- Original Message ----- From: "Macarty, Jay {PBSG}" <Jay.Macarty@xxxxxxxx> To: <programmingblind@xxxxxxxxxxxxx> Sent: Tuesday, November 11, 2008 3:43 PM Subject: RE: C# and COM - creating COM eventsDid take a little longer but I now have a sample C# class that exposes properties, methods, and events.
From: programmingblind-bounce@xxxxxxxxxxxxx[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Tyler Littlefield
Sent: Sunday, November 09, 2008 9:44 PM To: programmingblind@xxxxxxxxxxxxx Subject: Re: C# and COM - creating COM eventsnp--hope they helped. Incidentally, I think they might take a bit longer than 15 seconds.
Thanks, Tyler Littlefield email: tyler@xxxxxxxxxxxxx<mailto:tyler@xxxxxxxxxxxxx> web: tysdomain-com Visit for quality software and web design. skype: st8amnd2005 ----- Original Message ----- From: Macarty, Jay {PBSG}<mailto:Jay.Macarty@xxxxxxxx> To: programmingblind@xxxxxxxxxxxxx<mailto:programmingblind@xxxxxxxxxxxxx> Sent: Sunday, November 09, 2008 8:40 PM Subject: RE: C# and COM - creating COM events Tyler, The 15 Second articles definitely look promising. Thanks for the feedback! From: programmingblind-bounce@xxxxxxxxxxxxx<mailto:programmingblind-bounce@xxxxxxxxxxxxx>[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Tyler Littlefield
Sent: Saturday, November 08, 2008 6:38 PM To: programmingblind@xxxxxxxxxxxxx<mailto:programmingblind@xxxxxxxxxxxxx> Subject: Re: C# and COM - creating COM events Hello, Try this; it might help a bit. http://www.15seconds.com/issue/060309.htm this is geared toward javascript, but you can use the same ideas I think: http://channel9.msdn.com/forums/Coffeehouse/130000-Exposing-C-events-using-COM-to-JavaScript/I think creating an interface to create the delegate over would do the trick; not totally sure though. That's how I would expose methods, and then just use a get/set function for props--not sure how those would get exposed.
HTH, Thanks, Tyler Littlefield email: tyler@xxxxxxxxxxxxx<mailto:tyler@xxxxxxxxxxxxx> web: tysdomain-com Visit for quality software and web design. skype: st8amnd2005 ----- Original Message ----- From: Macarty, Jay {PBSG}<mailto:Jay.Macarty@xxxxxxxx> To: programmingblind@xxxxxxxxxxxxx<mailto:programmingblind@xxxxxxxxxxxxx> Sent: Saturday, November 08, 2008 5:22 PM Subject: C# and COM - creating COM events All,I have a C# program I am registering as a COM object. I have examples of creating properties and method calls. However, I also want this COM object to be able to produce events so that I can hook into those events from a VBScript script for Window-Eyes.
Any documentation or examples on exposing COM events from c# would be appreciated.
__________View the list's information and change your settings at //www.freelists.org/list/programmingblind
__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind __________View the list's information and change your settings at //www.freelists.org/list/programmingblind