Jump to content

Get Values from COM


Recommended Posts

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

Link to comment
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.

Link to comment
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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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
Link to comment
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)
Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...