I have a working RtdServer-based automation add-in:
How do I create a real-time Excel automation add-in in C# using RtdServer?.
Creating a VBA wrapper is trivial:
Function RtdWrapper(start)
RtdWrapper = Excel.Application.WorksheetFunction.RTD("StackOverflow.RtdServer.ProgId", "", start)
End Function
This works. I have attempted to create a C# wrapper as follows:
[ClassInterface(ClassInterfaceType.AutoDual)]
public class RtdWrappers
{
private readonly Microsoft.Office.Interop.Excel.Application _application = new Application();
public object Countdown(object startingCount)
{
var start = Convert.ToInt32(startingCount.ToString());
return _application.WorksheetFunction.RTD("StackOverflow.RtdServer.ProgId", string.Empty, start);
}
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("CLSID\\{" + t.GUID.ToString().ToUpper() + "}\\Programmable");
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey("CLSID\\{" + t.GUID.ToString().ToUpper() + "}\\Programmable");
}
}
When I enter "=Countdown(150)" into a cell in Excel it shows the initial value of 150 which is returned by ConnectData but never updates. Is there some callback that I should register? Am I instantiating the Application object correctly? What am I missing?
Thanks,
Frank