#C events in Navision

Hello All, Tommy Olesen had an example back in the 2003 but he did not say if he got it working or not so I have created a new topic. I have a VB example working nicly with events, methods. Does any one have a simple example and some instruction on how to create c# events. Look forward to your inputs Regards.

I used this page http://www.dotnettalk.net/Using_managed_event_from_window_script_host-6243121-1295-a.html as a reference. It works. The thing is, that Microsoft advises against stuff like ClassInterfaceType.AutoDual elsewhere, but i cannot bring it to work without it. I think managed events and interop has some flaws, and the M$ documentation on the subject is quite insufficient. By the way replace public type Button with public class Button

The link does not work [:S]

Right you are. It did when i posted it. Looks like some kind of server error. If it doesn’t come around in a few days i’ll try to post a sample.

One cannot even navigate to any topic on that page.

Well heres one that works (for me anyway, for now). You should replace the GUIDS with your own. What you will do in Navi is to make an Automation variable of type Button. Set Withevents to true. When you call the CausePulse method, you will get the Pulse event. I don’t understand all the stuff, but what i’ve learned is, that you need a lot of attributes in order to avoid broken references, if you plan to make future updates to your net dll. Make a strong named dll Please remember to use regasm your.dll /tlb gacutil /i your.dll When you install. If you recompile your dll, allways use regasm your.dll /u gacutil /u your (no dll extension) before you reinstall withl regasm your.dll /tlb gacutil /i your.dll Don’t use “Register for com interop” in VS2003. It sometimes confuses things, and regasm will do the stuff for you. Code: using System; using System.Runtime.InteropServices; namespace raiseevent { [ComVisible(false)] public delegate void PulseDelegate(); [GuidAttribute(“9CC9CCAE-B300-4794-B3A8-9960D43A57D5”)] [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] public interface ButtonEvents { [DispIdAttribute(1)] void Pulse(); } [GuidAttribute(“C0BEE88F-01EC-4755-8B0A-A20E0563428A”)] public interface iButton { [DispIdAttribute(2)] void CausePulse(); } [GuidAttribute(“38345F3F-ADDE-4089-B868-551EA7937528”)] [ClassInterface(ClassInterfaceType.None)] [ComSourceInterfaces(typeof(ButtonEvents))] public class Button : iButton { public Button() { } public void CausePulse() { Pulse(); } public event PulseDelegate Pulse; } } Hope it works for you too. No guarantees supplied. [xx(]

This should be the other way around If you recompile your dll, allways use regasm your.dll /u gacutil /u your (no dll extension) like this gacutil /u your (no dll extension) regasm your.dll /u