Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

COM Integration with other apps that require a type library?

If you have a question or need help, this is the place to be.
Post Reply
kingtd
Plugin Developer
Posts: 78
Joined: Fri Jul 13, 2007 7:39 am

COM Integration with other apps that require a type library?

Post by kingtd »

Thanks for everything you guys have done so far - your ability to make changes in the code in response to the various requests I see on here is amazing.

I'm working on doing some integration of Eventghost with some other apps I'm using and building. One of these apps is a C# app which gets the state from Windows Vista Media Center (VMC) and triggers events based on what the user does (moving around in the menus, playing a song, watching a DVD, etc).

When I try to link to the python com server, it's not a registered COM target. I think this is because it's missing a type library which defines which functions are available. From my research it looks like we need an IDL file which describes the functions you guys have published (basically TriggerEvent). I've been trying to work out exactly how to do this, but so far no luck.

Anyone out there with the experience to help sort this out? It looks like the kind of thing that, once built, could just be included with EG allowing it to be used as a COM target in most tools.

I have tested it with VBscript and it works fine there, but I can't get the state of VMC from VBscript so that's not an option for coding. Plus there are a ton of events that get created, so the normal 'run eventghost from the commandline' workaround would generate a lot of overhead.

I'll keep working on it and gladly post my results when I get it figured, but I wanted to see if anyone had the chops to move it forward a little faster.

Thanks!
-k
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: COM Integration with other apps that require a type library?

Post by Bitmonster »

I'm not sure if this is really needed from C#. It works with VBA so guess it will work with C# also. I just created a small VBA project in VS2003, added a button to the form and used this code:

Code: Select all

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim EventGhost
        EventGhost = CreateObject("EventGhost")
        EventGhost.TriggerEvent("Hello_from_VBA")
    End Sub
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
TomXP411
Posts: 25
Joined: Thu Oct 30, 2008 4:13 pm

Re: COM Integration with other apps that require a type library?

Post by TomXP411 »

Sorry about the necropost, but I'm running in to the same problem.

Without a COM type library, you can't interface with EventGhost from a .Net language. You can use VBScript and VBA because they're COM-based and late-bound. Like the OP, I can create a VBA or VBS and trigger EventGhost events, but I can't do the same with a C# or VB.Net app.

The obvious answer was to try to reference EventGhost.exe, but it's not a valid COM object, so I'm kind of stuck.

Is there any documentation on the specific events and methods that EG supports?

Ideally, I'd like to lead up to being able to write my own plugin for EventGhost to directly support an application I'm writing.

Thanks
jsonnabend
Experienced User
Posts: 127
Joined: Wed Apr 23, 2008 7:35 pm

Re: COM Integration with other apps that require a type library?

Post by jsonnabend »

VB, like most Windows languages, can early bind or late bind.

C# can late bind to COM objects as well, according to what I have read. See, for example, this article.

- Jeff
TomXP411
Posts: 25
Joined: Thu Oct 30, 2008 4:13 pm

Re: COM Integration with other apps that require a type library?

Post by TomXP411 »

Good find, Jeff.

I was going down that road yesterday, but I got sidetracked by trying to manually build an Interop DLL.

Here's what I came up with:

Code: Select all

    
    private void TriggerEvent(string EventName, string Payload)
    {
      Object[] Params;
      Type EventGhost = Type.GetTypeFromProgID("EventGhost");
      object myObject = Activator.CreateInstance(EventGhost);
      Params = new Object[] { EventName, Payload };
      EventGhost.InvokeMember("TriggerEvent", BindingFlags.InvokeMethod, null,
      myObject, Params);
    }
Attachments
EGTest.zip
VC#2008 project that raises events in EventGhost
(43.65 KiB) Downloaded 197 times
Post Reply