Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I access my c# objects from my external .dll? Maybe using ROT
    text
    copied!<p>I have a c# application that runs locally, and I have a .dll written in c#.</p> <p>MyApplication contains</p> <pre><code>namespace MyApplication { public interface IMyInterface { IMyInterface Instance { get; } int MyProp { get; } } class MyClass : IMyInterface { public int MyProp { get; private set; } private MyClass instance public static IMyInterface { get { if (instance == null) { instance = new MyClass(); } return instance; } } private MyClass() { MyProp = 1; } } } </code></pre> <p>MyLibrary:</p> <pre><code>namespace MyLibrary { public LibClass { public static int GetProp() { //I want to get the running instance of MyApplication //If MyApplication is not running I want to start a new instance //From my application instance I want to //return the value from MyInterface.Instance.MyProp } } } </code></pre> <p>Some googling has me looking at a COM server of sorts, but it wasn't clear if that was the best approach. I am having trouble even knowing what to google for this one. Ultimately <code>MyInterface</code> Will get a lot more complex and will include events to notify <code>MyLibrary</code> to refresh the data. How is the best way to accomplish this? Is it a COM server? Do I want to create some sort of API in <code>MyApplication</code> that <code>MyLibrary</code> uses?</p> <p><em>Additional Information:</em></p> <p>My .dll is being created as a real time data server for excel. I want to be able to access the data within my application from excel and notify excel of refreshes. I don't want to have multiple instances of my application since user input will determine the values displayed in excel. I am able to create the rtd server, however I am not sure what the best way is to access my outside data.</p> <p><strong>EDIT:</strong></p> <p>After doing some more research I think I am interested in using <code>GetActiveObject("MyApplication.IMyInterface")</code> inside <code>MyLibrary</code> to look like</p> <pre><code>namespace MyLibrary { public LibClass { public static int GetProp() { running_obj = System.Runtime.InteropServices.Marshal.GetActiveObject("MyApplication.IMyInterface") return ((IMyInterface) running_obj).MyProp; } private object running_obj = null; } } </code></pre> <p>But I am not sure how to register <code>MyApplication.MyClass</code> in the ROT. The code as is throws an exception</p> <pre><code>Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING)) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload