grossmeisterbm Posted August 30, 2012 Share Posted August 30, 2012 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 More sharing options...
Andreik Posted August 30, 2012 Share Posted August 30, 2012 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 More sharing options...
grossmeisterbm Posted August 30, 2012 Author Share Posted August 30, 2012 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 More sharing options...
grossmeisterbm Posted August 31, 2012 Author Share Posted August 31, 2012 (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 August 31, 2012 by grossmeisterbm Link to comment Share on other sites More sharing options...
trancexx Posted August 31, 2012 Share Posted August 31, 2012 (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 August 31, 2012 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
grossmeisterbm Posted August 31, 2012 Author Share Posted August 31, 2012 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 . Link to comment Share on other sites More sharing options...
trancexx Posted August 31, 2012 Share Posted August 31, 2012 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 Link to comment Share on other sites More sharing options...
grossmeisterbm Posted August 31, 2012 Author Share Posted August 31, 2012 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 More sharing options...
trancexx Posted August 31, 2012 Share Posted August 31, 2012 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 Link to comment Share on other sites More sharing options...
grossmeisterbm Posted September 3, 2012 Author Share Posted September 3, 2012 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? Link to comment Share on other sites More sharing options...
trancexx Posted September 3, 2012 Share Posted September 3, 2012 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 Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 4, 2012 Share Posted September 4, 2012 That's effectively a LPCWSTR varName, unsigned long *value. Link to comment Share on other sites More sharing options...
grossmeisterbm Posted September 4, 2012 Author Share Posted September 4, 2012 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 More sharing options...
grossmeisterbm Posted September 7, 2012 Author Share Posted September 7, 2012 No new ideas? :-( Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now