How to pass a struct parameter using TCOM in Tcl

1

I've inherited a piece of custom test equipment with a control library built in a COM object, and I'm trying to connect it to our Tcl test script library. I can connect to the DLL using TCOM, and do some simple control operations with single int parameters. However, certain features are controlled by passing in a C/C++ struct that contains the control blocks, and attempting to use them in TCOM is giving me an error 0x80020005 {Type mismatch.}. The struct is defined in the .idl file, so it's available to TCOM to use.

The simplest example is a particular call as follows:

C++ .idl file:

struct SourceScaleRange
{
    float MinVoltage;
    float MaxVoltage;
};
interface IAnalogIn : IDispatch{
...
    [id(4), helpstring("method GetAdcScaleRange")] HRESULT GetAdcScaleRange(
        [out] struct SourceScaleRange *scaleRange);
...
}

Tcl wrapper:

::tcom::import [file join $::libDir "PulseMeas.tlb"] ::char
set ::characterizer(AnalogIn)  [::char::AnalogIn]
set scaleRange ""
set response [$::characterizer(AnalogIn) GetAdcScaleRange scaleRange]

Resulting error:

0x80020005 {Type mismatch.}
    while executing
"$::characterizer(AnalogIn) GetAdcScaleRange scaleRange"
    (procedure "charGetAdcScaleRange" line 4)

When I dump TCOM's methods, it knows of the name of the struct, at least, but it seems to have dropped the struct keyword. Some introspection code

set ifhandle [::tcom::info interface $::characterizer(AnalogIn)]
puts "methods: [$ifhandle methods]"

returns

methods: ... {4 VOID GetAdcScaleRange {{out {SourceScaleRange *} scaleRange}}} ...

I don't know if this is meaningful or not.

At this point, I'd be happy to get any ideas on where to look next. Is this a known TCOM limitation (undocumented, but known)? Is there a way to pre-process the parameter into an appropriate format using tcom? Do I need to force it into a correctly sized block of memory via binary format by manual construction? Do I need to take the DLL back to the original developer and have him pull out all the struct parameters? (Not likely to happen, in this reality.) Any input is good input.

com
tcl
asked on Stack Overflow Dec 4, 2013 by Erik Johnson

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0