Sign in to follow this  
Followers 0
grossmeisterbm

Get Values from COM

14 posts in this topic

Hello,

I want to read values from a com-module.

I found the following function with the ole object viewer:

[id(0x0000002e)]
HRESULT GetVariable_UINT32(
             [in] BSTR varName,
             [in, out] unsigned long* value,
             [out, retval] long* pRetVal);

I tried this in AutoIt.

$o_TTX=ObjCreate("TTXConnexion.TestController")
$retval = $o_TTX.GetVariable_UINT32('var1',$Value)

While running the script there are no errors. $retval is always 0 that means everything is OK.

But the value of $Value did not change. I think $Value had to be a pointer. But I've got no idea how to do this in AutoIt.

Any suggestions

Share this post


Link to post
Share on other sites



Try this:

$Value = DllStructCreate("ulong Value")
$o_TTX = ObjCreate("TTXConnexion.TestController")
$retval = $o_TTX.GetVariable_UINT32('var1',DllStructGetPtr($Value))

MsgBox(0,"Value",DllStructGetData($Value,"Value"))

I'm not very sure if this will work but if you can send me the COM module I can try to make it work.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Hi,

thank you for your fast answer.

I manually set the variable in the hardware (i want to "talk" to) to a value different to 0.

The script runs well. But $Value is still 0.

It is difficult to send you the com module because it will only work with as special hardware connected by usb.

Do you have any other ideas?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi,

I talked to the developer of the hardware and he send me some lines of C-code which should work.

Here's the code:

#include "stdafx.h"
#include <string>
#include <stdio.h>

/* Initialisieren der COM-Schnittstelle */
TTXConnexionConfig::_TestController *TestCtrl;

/* Initialisieren der Rückgabevariablen */
HRESULT result;
long *RetVal = (long *)malloc(sizeof(long));

/* Code zum Lesen einer Variablen*/
BSTR strTest;
float value;
result = TestCtrl->GetVariable_FLOAT(strTest, &value, RetVal);

Sorry for the German comments :-)

Do anybody know what's the difference between &value and value in C?

Edited by grossmeisterbm

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

One is pointer, other is not.

Developer didn't give you Automation example. Thell him you want to access that method through IDispatch, not directly.

[in,out] parameters are sometimes tricky depending how the dev implements dispatch. Try something like this and post the results:

$o_TTX = ObjCreate("TTXConnexion.TestController")

$iValue = 0 ; <-
$iRetval = $o_TTX.GetVariable_UINT32('var1', $iValue)

ConsoleWrite("@error = " & @error & @CRLF)
ConsoleWrite("$iValue = " & $iValue & @CRLF)
ConsoleWrite("$iRetval = " & $iRetval & @CRLF)
Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Ok I tried this, here's the output of the console:

error = 0

$iValue = 0

$iRetval = 0

Can you shortly describe what you mean with automation example and where the difference is between IDispatch and direct method .

Share this post


Link to post
Share on other sites

What values for $iValue and $iRetval did you expect? That output looks just fine.

In oreder to explain the differences I would have to explain the concepts of early binding and late binding, IDispatch interface, dual interface, etc... Just google underlined terms.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Like you said, output looks fine.

But I manually set the value for "var1" to 16 directly in the hardware.

And I aspect that value as result for the "GetVariable_UINT32-function"

$iRetval = 0 means that the function was completed successfully (1 is error)

It seems that the function does not write the value correctly to the pointer position

Share this post


Link to post
Share on other sites

It seems that the function does not write the value correctly to the pointer position

Not necessarily. This could very well be bug on our side. I can imagine situation like this happening once in million times. Maybe this is it.

...I'll fix it assuming that.

If you are in contact with autor then ask him what type is his VARIANT

[in, out] unsigned long* value

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

I talked to de developer and he sent me this original code from the interface.

The interface is programmed in VB.net.

Function GetVariable_UINT32(ByVal varName As String, ByRef value As UInt32) As Integer

Is this helpful in any way?

Share this post


Link to post
Share on other sites

Actually it's not. I don't know what .NET marshals that object to.

System type to VARIANT or particularly ByRef UInt32 to VARIANT.

When new version of AutoIt would be out you'll get chance to test the changes, unless you provide me with Type Library of that object. In that case I'll know for sure. The path of the file is printed to console here:

ConsoleWrite(ObjName(ObjCreate("TTXConnexion.TestController"), 4) & @CRLF)

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

That's effectively a LPCWSTR varName, unsigned long *value.

Share this post


Link to post
Share on other sites

trancexx suggested to try the following

$o_TTX = ObjCreate("TTXConnexion.TestController")

$sVarName = "DummyName"

$iVal = 567

$iRetSet = $o_TTX.SetVariable_INT32($sVarName, $iVal)

ConsoleWrite("Set @error = " & @error & @CRLF)

ConsoleWrite("$iRetSet = " & $iRetSet & @CRLF & @CRLF)


$iReadValue = -1

$iRetGet = $o_TTX.GetVariable_INT32($sVarName, $iReadValue)


ConsoleWrite("Get @error = " & @error & @CRLF)

ConsoleWrite("$iReadValue = " & $iReadValue & @CRLF)

ConsoleWrite("$iRetGet = " & $iRetGet & @CRLF)

and this is the result from the console:

Set @error = 0

$iRetSet = 0

Get @error = 0

$iReadValue = -1

$iRetGet = 0

Share this post


Link to post
Share on other sites

No new ideas? :-(

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