Why doesn't ADXRTDServerModule.Connect have a return value?

Add-in Express™ Support Service
That's what is more important than anything else

Why doesn't ADXRTDServerModule.Connect have a return value?
 
David Jones


Guest


Hi there

I realise that this question has been touched upon in other threads (e.g. http://www.add-in-express.com/forum/read.php?PAGEN_1=1&FID=5&TID=6992#nav_start), but why does the ADX version of Connect not have a return value? Is this something that could be changed? We currently have to implement a workaround to handle this.

Thanks very much

David
Posted 17 Jun, 2013 07:46:57 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello David,

I can't find the Connect method on the ADXRTDServerModule. Are you talking about the ADXRTDServerModule.ConnectData method, the Connect event of the ADXRTDTopic component or some other member? Can you please describe how you would like to use it?


Andrei Smolin
Add-in Express Team Leader
Posted 17 Jun, 2013 08:40:53 Top
David Jones


Guest


Hi Andrei

Sorry - I did mean ADXRTDServerModule.ConnectData.

Presumably this is implementing the following interface:

HRESULT __stdcall ConnectData(/*[in]*/ long topicId,
                              /*[in]*/ SAFEARRAY** strings,
                              /*[in,out]*/ VARIANT_BOOL* newValues,
                              /*[out]*/ VARIANT* values) override;


(taken from Kenny Kerr's RTD server pages: http://weblogs.asp.net/kennykerr/archive/2008/12/02/Rtd5.aspx)

As you can see there is a out parameter. The .NET implementation of ConnectData returns this as an object:

object ConnectData(
	[In] int TopicID, 
	[In] ref Array Strings, 
	[In, Out] ref bool GetNewValues
);


(link here: http://msdn.microsoft.com/en-gb/library/microsoft.office.interop.excel.irtdserver.connectdata(v=office.11).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2)

However, the ADX implementation of ConnectData does not return anything:

private void myRTD_Connect(object sender, EventArgs e)
{
...


There is a forum post that touches on this here: http://www.add-in-express.com/forum/read.php?FID=5&TID=9076 but it does not explain why it's not returning the value.

We have a problem with one of our functions that would be easy to solve if we could return a value from ConnectData. Instead we have had to implement a workaround. Is this something that could be changed?

Thanks very much

David
Posted 20 Jun, 2013 05:09:46 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
David,

Note that the return value is HRESULT. And this value is given back to the caller for interpreting. Since the caller is Excel, I wonder what you return to Excel and how it interprets this.


Andrei Smolin
Add-in Express Team Leader
Posted 20 Jun, 2013 06:11:36 Top
David Jones


Guest


It's the fourth parameter (/*[out]*/ VARIANT* values) in this interface that I want to get access to:

HRESULT __stdcall ConnectData(/*[in]*/ long topicId, 
                              /*[in]*/ SAFEARRAY** strings, 
                              /*[in,out]*/ VARIANT_BOOL* newValues, 
                              /*[out]*/ VARIANT* values) override;


This is the object that is returned by the .NET ConnectData implementation.

Thanks

David
Posted 20 Jun, 2013 06:56:10 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
David,

The implementation of the ConnectData method invokes the Connect event of the ADXRTDTopic component. In this event, you can set the ADXRTDTopic.Default value.

object AddinExpress.RTD.IRtdServer.ConnectData(int topicID, ref System.Array strings, ref bool getNewValues)
{
    object retVal = String.Empty;

    if (strings != null)
    {
        AddinExpress.RTD.ADXRTDTopic adxTopic = null;
        string fullString = String.Empty;
        for (int i = 0; i < strings.Length; i++)
        {
            fullString += (string)strings.GetValue(i);
        }
        int index = IndexOfTopicStrings(fullString);
        if (index >= 0)
            adxTopic = ADXTopicCollection.Topics[index] as AddinExpress.RTD.ADXRTDTopic;
        else
            adxTopic = FindNestedTopic(strings, ref index);
        if (adxTopic != null)
        {
            adxTopic.InternalTopicID = topicID;
            ADXTopicCollection.TopicsID[topicID] = index;

            try
            {
                adxTopic.DoConnect();
            }
            catch (Exception e)
            {
                DoError(this, ADXExternalException.Wrap(e));
            }

            if (adxTopic.OldValue != null)
            {
                getNewValues = true;
                retVal = adxTopic.OldValue;
            }
            else
            {
                getNewValues = !adxTopic.UseStoredValue;
                if (getNewValues)
                    retVal = adxTopic.DefaultValue;
            }
        }
        else
            retVal = "Unrecognized";
    }
    return retVal;
}


retVal is that out parameter.


Andrei Smolin
Add-in Express Team Leader
Posted 20 Jun, 2013 09:42:24 Top
David Jones


Guest


Hi Andrei - I've just got around to testing this approach and it does exactly what I want. Thanks very much!

David
Posted 28 Jun, 2013 08:19:20 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 28 Jun, 2013 08:24:10 Top