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}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface IScripRTD;
interface IRTDUpdateEvent;
[
uuid(A04A3240-D051-4B4C-B004-CA92151F11E5),
helpstring("ScripRTD Class")
]
coclass ScripRTD {
[default] interface IScripRTD;
};
[
odl,
uuid(EC0E6191-DB51-11D3-8F3E-00C04F3651B8),
helpstring("IScripRTD Interface"),
dual,
nonextensible,
oleautomation
]
interface IScripRTD : IDispatch {
[id(0x0000000a)]
HRESULT ServerStart(
[in] IRTDUpdateEvent* callback,
[out, retval] long* result);
[id(0x0000000b)]
HRESULT ConnectData(
[in] long topicId,
[in] SAFEARRAY(VARIANT)* strings,
[in, out] VARIANT_BOOL* newValues,
[out, retval] VARIANT* values);
[id(0x0000000c)]
HRESULT RefreshData(
[in, out] long* topicCount,
[out, retval] SAFEARRAY(VARIANT)* data);
[id(0x0000000d)]
HRESULT DisconnectData([in] long topicId);
[id(0x0000000e)]
HRESULT Heartbeat([out, retval] long* result);
[id(0x0000000f)]
HRESULT ServerTerminate();
};
[
odl,
uuid(A43788C1-D91B-11D3-8F39-00C04F3651B8),
dual,
oleautomation
]
interface IRTDUpdateEvent : IDispatch {
[id(0x0000000a)]
HRESULT UpdateNotify();
[id(0x0000000b), propget]
HRESULT HeartbeatInterval([out, retval] long* value);
[id(0x0000000b), propput]
HRESULT HeartbeatInterval([in] long value);
[id(0x0000000c)]
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 -
get_price(symbol)
{
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.
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
User contributions licensed under CC BY-SA 3.0