Excel RTD Servers: C# Interfaces
So it turns out that there are in fact quite a few
developers who care about writing RTD servers. I’ve received
a few emails asking for more information so I may post a few
more entries on the subject. Last time I simply showed what
the
RTD server interfaces look like in C++. Here’s the equivalent in C#:
[Guid("A43788C1-D91B-11D3-8F39-00C04F3651B8")]
interface
IRTDUpdateEvent
{
void UpdateNotify();
int HeartbeatInterval { get; set; }
void
Disconnect();
}
[Guid("EC0E6191-DB51-11D3-8F3E-00C04F3651B8")]
interface
IRtdServer
{
int ServerStart(IRTDUpdateEvent
callback);
object ConnectData(int
topicId,
ref Array strings,
ref bool newValues);
Array RefreshData(ref
int topicCount);
void DisconnectData(int
topicId);
int Heartbeat();
void ServerTerminate();
}
Of course what these interfaces look like and
how they are actually called by Excel are two very different
things thanks to the
horrors
wonders of IDispatch.
I’m including C# in the
discussion as its very tempting for .NET developers to
implement an RTD server in managed code. Unfortunately it’s
easy to forget that you still need to follow the rules
outlined by the COM specification. If you don’t, it will
come back to haunt you later on.