NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass sequence context object reference (IDispatch pointer) to COM Server method

I put together a simple out-of-process com server (local) with one interface derived from IUnkknown and a handful of methods. One of the methods takes a teststand sequence context pointer as a parameter. The project compiles, but I can't get that one method to work. My server crashes when Teststand calls it, and I get a run-time error in TestStand. The prototype of the method is question is: STDMETHODIMP NewMethod(IDispatch *pDispContext); . At this point I removed alll the code from the method implementation so it just returns S_OK. The run-time error I am getting from TestStand when calling this method is: -2147023116; User-defined error code. Possible System Error: A null reference pointer was passed to the stub.
 
The sequence I use to test this has one Activex/COM action step and the method parameter pDispContext shows up in the step settings as an object reference. The value I enter pDispContext is 'ThisContext'.

1. My understanding is that I should be able to do this. Am I wrong?
2. The only way I can get the server to not crash on the method call is to change the method prototype to use the VARIANT data type instead of IDispatch. However, subsequently adding code to use the VARIANT pointer that was passed in to cast it to a TS::SequenceContext pointer (not TS::SequenceContextPtr) gives me trouble as well.

I understand that although TestStand is involved in the mix, this is probably a more basic COM implementation issue, but I have not been able to find an COM example for this...

Help!

0 Kudos
Message 1 of 4
(4,302 Views)
Hello freak,

You may want to try passing the sequence context in as literally a SequenceContext pointer, like this:

STDMETHODIMP NewMethod(SequenceContext *pDispContext)

SequenceContext implements the IDispatch interface and should work for you.  For a demonstration of how this has been implemented in some of our examples, you can have a look at C:\Program Files\National Instruments\TestStand x.x\Examples\AccessingArraysUsingAPI\UsingMFC.  This example has multiple methods that take the sequence context as a parameter.

NickB
National Instruments
Applications Engineering
0 Kudos
Message 2 of 4
(4,272 Views)
Nick,
Thanks for the reply. Since my original post I figured out that I can't successfully pass any IDispatch pointer into my COM object method, unless the server is in-process. It looks to me like the marshalling between the client and the server is the culprit and needs more work. Also, I have implemented several code modules (DLLs) in the past with methods that have a Dispatch or sequence context pointer as a parameter, but this is different because of having to cross process boundaries. Any advice that would get me there quicker?
 
Thanks
0 Kudos
Message 3 of 4
(4,255 Views)
Hello Freak,

As I was looking into your issue a little further, I found another example that we have written which is an out of process COM server that takes the sequence context as a parameter.  From all I can tell, it seems like you are doing things correctly, but perhaps if you were to have a look at the example, you may find some discrepancies.  This is a new example that ships with TestStand 4.1, so if you do not yet have TestStand 4.1 installed, you can download the evaluation version here to see the source code for the server. 

You can find the example at the following path:
C:\Documents and Settings\All Users\Documents\National Instruments\TestStand 4.1\Examples\Tcl\source

In particular have a look starting at line 186 of the file TclInterpreter.cpp.  This introduces the following method:
STDMETHODIMP CTclInterpreter::ExecuteStep(IDispatch * context)

Have a look at that and if things still do not begin to fall into place, don't hesitate to let us know.

NickB
National Instruments
Applications Engineering
0 Kudos
Message 4 of 4
(4,227 Views)