C# COM client (RTD)


I'm working with a real time data server (a trading terminal) that has a COM interface for ticker updates. From Excel, I'm able to subscribe to the ticker updates using this -

RTD(progId,,topic1,topic2, ...)

I'm trying to build an application that will receive these ticker updates without any dependency on Excel or any of its APIs. I'm a Java developer with no experience in MS technologies, but I thought I'd give this a shot in C#.

I used OleView to dig up this TypeLib

// TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}

// Forward declare all types defined in this typelib
interface IScripRTD;
interface IRTDUpdateEvent;

  helpstring("ScripRTD Class")
coclass ScripRTD {
    [default] interface IScripRTD;

  helpstring("IScripRTD Interface"),
interface IScripRTD : IDispatch {
    HRESULT ServerStart(
                    [in] IRTDUpdateEvent* callback, 
                    [out, retval] long* result);
    HRESULT ConnectData(
                    [in] long topicId, 
                    [in] SAFEARRAY(VARIANT)* strings, 
                    [in, out] VARIANT_BOOL* newValues, 
                    [out, retval] VARIANT* values);
    HRESULT RefreshData(
                    [in, out] long* topicCount, 
                    [out, retval] SAFEARRAY(VARIANT)* data);
    HRESULT DisconnectData([in] long topicId);
    HRESULT Heartbeat([out, retval] long* result);
    HRESULT ServerTerminate();

interface IRTDUpdateEvent : IDispatch {
    HRESULT UpdateNotify();
    [id(0x0000000b), propget]
    HRESULT HeartbeatInterval([out, retval] long* value);
    [id(0x0000000b), propput]
    HRESULT HeartbeatInterval([in] long value);
    HRESULT Disconnect();

I came across this example, but the part about using TlbImp to autogenerate the C# interfaces is not clear to me. Could someone provide a better example of how to instantiate this interface and register a callback to get the ticker updates?

Incidentally, I was able to whip up a quick AHK script that comes close to what I'm looking for -

    comObj := ComObjCreate(progId)
    num := ComObjParameter(3, 5)
    update := ComObjParameter(0xB, -1)
    arr := ComObjArray(VT_VARIANT:=12, 3)
    arr[0] := "MktWatch"
    arr[1] := symbol
    arr[2] := "Last Traded Price"
    price := comObj.ConnectData(num, arr, update )
    return price 

This does not register a callback, but if I run this with a timer, I'm able to get ticker updates for individual symbols.

In case it makes a difference, I'm using Win 7 x64.

I have looked at this example, which seems to use reflection instead of declaring the COM interface, but I couldn't get it to work.

asked on Stack Overflow Oct 13, 2012 by Vivek • edited May 23, 2017 by Community

1 Answer


What's not clear about using TlbImp.exe? Seems pretty easy to me: use it to convert a COM type library to a .NET assembly, add a reference to that assembly from your C# project, and then use it like any other .NET assembly.

And actually, you don't really need to use TlbImp.exe at all, just add a reference to the type library as mentioned in the MSDN article you mentioned.

Anyway, here's another article that explains importing type libraries in more detail: http://msdn.microsoft.com/en-us/library/xwzy44e4.aspx

answered on Stack Overflow Oct 13, 2012 by user1610015

User contributions licensed under CC BY-SA 3.0