views:

153

answers:

1

How do I make instances of and calls to COM components that have been extended?

I have used a third party COM component (XRawFile2.dll from Finnigan/ Thermo Scientific) for many years in a mass spectrometry related application written in .NET (mixed VB.NET and C#) for accessing raw spectrum data. This has worked well. However this COM component has been extended by way of interface inheritance. Expressed in IDL (extracted using the OLE/COM Object Viewer [OleView.Exe]):

interface IXRawfile3 : IXRawfile2 {
.
.

interface IXRawfile2 : IXRawfile {
.
.

interface IXRawfile : IDispatch {
.
.

coclass XRawfile {
    [default] interface IXRawfile;
};

The full extracted IDL for XRawFile2.dll is available (HTML page with <pre>).

I want to use a function available in the new interface (IXRawfile3),

GetMassListRangeFromScanNum()

instead of

GetMassListFromScanNum()

in the original interface (IXRawfile).

I have no trouble creating an instance of XRawFile and calling GetMassListFromScanNum(). But I can't get it to work with GetMassListRangeFromScanNum(). For instance using GetMassListRangeFromScanNum() for an instance of XRawFile gives this compile error:

  Error 1 'XRAWFILE2Lib.XRawfile' does not contain a 
  definition for 'GetMassListRangeFromScanNum' and no 
  extension method 'GetMassListRangeFromScanNum' accepting a 
  first argument of type 'XRAWFILE2Lib.XRawfile' could be 
  found (are you missing a using directive or an assembly 
  reference?)

The tryout C# source code is also available.

Platform: Windows XP 64 bit SP2. Visual Studio 2008. The interop file for XRawFile2.dll was created by Visual Studio 2008 in the normal manner.

+1  A: 

Try casting your instance of XRawFile to IXRawfile3

e.g.

( (IXRawfile3) myRawFile ).GetMassListRangeFromScanNum()

This should do a query interface on the COM object, asking it for the IXRawfile3 interface. (Assuming the typelib you have imported does match the implementation of XRawfile)

Ian Ringrose
That actually worked. Thanks! The returned data points were also as expected.
Peter Mortensen