Sign in to follow this  
Followers 0
Postman

Return values from calling a COM function

7 posts in this topic

Hiho,

I want to call a function from a certain COM component which has multiple return (out) values.

The corresponding IDL line for this function looks like following:

HRESULT Logout([out] BSTR* test1, [out, retval] VARIANT* test2);

The c++ function declaration looks as follows:

STDMETHODIMP MyClass::Logout(BSTR* test1, VARIANT* test2);

When I call the function with Autoit...

Local $test1, $test2
    $test2 = $MYCOM.Logout($test1)
    Msg($test1)
    Msg($test2)

"$test2" contains the correct value but "$test1" is empty. But if call it using VBscript both variables contain the correct values.

test2 = MYCOM.Logout(test1)
MsgBox(test1)
MsgBox(test2)

Has anybody an explanation? Does AutoIT support multiple return values?

with kind regards

Share this post


Link to post
Share on other sites



What is the syntax or the successful call in VBScript?

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

What is the syntax or the successful call in VBScript?

Dale

Hi Dale,

it is the third listing of code:

test2 = MYCOM.Logout(test1)
MsgBox(test1)
MsgBox(test2)

The variables are declared previously with 'Dim'.

Usually I would declare the called function of my COM object without 'retval' and only with 'out'. So when I use it c++, the function simply manipulates the object of the giving pointers and a have the return values. When I call the function of my COM object with AutoIt using two AutoIt variables, the variables are still empty after the function call. The only approach which works with AutoIt is to declare one of the [out] parameters as 'retval' so that I can use the '=' operator ($test2 = $MYCOM.Logout($test1)).

Robert

Edited by Postman

Share this post


Link to post
Share on other sites

Hi Dale,

it is the third listing of code:

test2 = MYCOM.Logout(test1)
MsgBox(test1)
MsgBox(test2)

The variables are declared previously with 'Dim'.

Usually I would declare the called function of my COM object without 'retval' and only with 'out'. So when I use it c++, the function simply manipulates the object of the giving pointers and a have the return values. When I call the function of my COM object with AutoIt using two AutoIt variables, the variables are still empty after the function call. The only approach which works with AutoIt is to declare one of the [out] parameters as 'retval' so that I can use the '=' operator ($test2 = $MYCOM.Logout($test1)).

Robert

The asterisks mean both test1 and test2 are ByRef, don't they? I would have tried:
Local $test1, $test2, $RET
$RET = $MYCOM.Logout($test1, $test2)

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The asterisks mean both test1 and test2 are ByRef, don't they? I would have tried:

Local $test1, $test2, $RET
$RET = $MYCOM.Logout($test1, $test2)

:)

Yes, both are ByRef. But AutoIt does not seem to recognize it.

Your function call '$RET = $MYCOM.Logout($test1, $test2)' does not work, because the second variable is marked as 'retval' in the IDL file of our COM interface. So the value of this variable is returned by the "="-operator the function cannout be called with two parameters. Calling the function:

HRESULT Logout([out] BSTR* test1, [out, retval] VARIANT* test2);
with AutoIt returns only the changed value for 'test2' by the "="-operator.

If we change the IDL signature from '[out,retval]' to '[out]' - AutoIt does not return any values.

with kind regards

Share this post


Link to post
Share on other sites

This is exactly our problem:

AutoIt and COM objects Byref

AutoIt feature request

Is it solved?

Doh! I've seen that issue before and should have remembered it. :)

I remember Valik saying ByRef COM objects involved fundamental changes in AutoIt. The Devs have not figured it out yet, and it's not a high priority.

Can you change the call to go directly to a .dll vice a COM interface? There is an AutoIt mechanism to pass ByRef's in DllCall().

I know that doesn't help if your app wasn't built that way, but it's all I could think of, and the COM ByRef fix is not coming any time soon.

:o


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0