Book a Demo

Author Topic: Accessing the running instance of EA from C#  (Read 4426 times)

sawek84

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Accessing the running instance of EA from C#
« on: February 06, 2009, 11:13:27 am »
I'd like to access the running instance of EA from C#, i.e. perform some operations on already opened file - how do I do it?

I tried something like that:
EA.AppClass App = new EA.AppClass();
App.Repository.OpenFile("C:\\Program Files\\Sparx Systems\\EA Trial\\EAExample.eap")

but it creates another instance which is disposed after my C# application is terminated.
Could anyone help me with that (maybe provide a couple of lines of code)?

Regards

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Accessing the running instance of EA from C#
« Reply #1 on: February 06, 2009, 11:51:23 am »
To access a running instance of EA, you need to use the equivilent of the GetObject() call as shown in the VB example on the App page.  For C#, try something like this..

Code: [Select]
using System.Runtime.InteropServices;
...
object obj = Marshal.GetActiveObject("EA.App");
EA.App app = obj as EA.App;
EA.Repository rep = app.Repository;

sawek84

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Accessing the running instance of EA from C#
« Reply #2 on: February 06, 2009, 12:17:54 pm »
Thanks a lot. It works exactly as intended :)

Regards