Jump to content
ranber

How pass autoit variant to a COM method

Recommended Posts

ranber

Hi ~ I have a OCX file and its IDL like below:
 

// Generated .IDL/C++ pseudo source equivalent of Win32 type library ..\CZEMApi.ocx
[
  uuid({71BD42C1-EBD3-11D0-AB3A-444553540000}),
  version(1.0),
  helpstring("CZ EM API OLE Control")
]
library APILib
{
    // Forward references and typedefs
    dispinterface _EMApi;
    dispinterface _EMApiEvents;

    [
      uuid({71BD42C2-EBD3-11D0-AB3A-444553540000}),
      helpstring("Dispatch interface for CZ EM API Control")
    ]
    dispinterface _EMApi
    {
        properties:
            [id(0), bindable, requestedit] BSTR Caption;
        methods:
            [id(0)] long Set(
                            BSTR lpszParam,
                            VARIANT* vValue);
            [id(1)] long Get(
                            BSTR lpszParam,
                            VARIANT* vValue);
            [id(2)] long Execute(BSTR lpszCommand);
            [id(3)] long Initialise(BSTR lpszMachine);
            [id(4)] long Grab(
                            short xoff,
                            short yoff,
                            short width,
                            short height,
                            short reduction,
                            BSTR lpszFilename);
            [id(5)] long GetStagePosition(
                            VARIANT* x,
                            VARIANT* y,
                            VARIANT* z,
                            VARIANT* t,
                            VARIANT* r,
                            VARIANT* m);
            [id(6)] long MoveStage(
                            single x,
                            single y,
                            single z,
                            single t,
                            single r,
                            single m);
            [id(7)] long SetNotify(
                            BSTR lpszParameter,
                            long bNotify);
            [id(8)] long GetLastError(VARIANT* Error);
            [id(9)] long ClosingControl();
            [id(10)] long GetLimits(
                            BSTR lpszParam,
                            VARIANT* vMinValue,
                            VARIANT* vMaxValue);
            [id(11)] long GetMulti(
                            BSTR lpszParam,
                            VARIANT* vValues);
            [id(12)] long SetMulti(
                            BSTR lpszParam,
                            VARIANT* vValues);
            [id(13)] long GetVersion(short* Version);
            [id(14)] long InitialiseRemoting();
            [id(15)] long GetCurrentUserName(
                            BSTR* strServerUserName,
                            BSTR* strNTUserName);
            [id(16)] long GetUserIsIdle(long* bUserIsIdle);
            [id(17)] long GetLastRemotingConnectionError(BSTR* strLastConnectionError);
            [id(18)] long SetSuppressRemotingConnectionErrors();
            [id(19)] long LogonToEMServer(
                            BSTR lpszUserName,
                            BSTR lpszUserPassword);
            [id(20)] long StartEMServer();
            [id(21)] long MoveStageDoubles(
                            double x,
                            double y,
                            double z,
                            double t,
                            double r,
                            double m);
            [id(22)] void AboutBox();
    };

    [
      uuid({71BD42C3-EBD3-11D0-AB3A-444553540000}),
      helpstring("Event interface for CZ EM API Control")
    ]
    dispinterface _EMApiEvents
    {
        properties:
        methods:
            [id(0)] void Notify(
                            BSTR lpszParameter,
                            long Reason);
            [id(1)] void NotifyWithCurrentValue(
                            BSTR lpszParameter,
                            long Reason,
                            long paramid,
                            double dLastKnownValue);
    };

    [
      uuid({71BD42C4-EBD3-11D0-AB3A-444553540000}),
      helpstring("CZ EM API Control")
    ]
    coclass Api
    {
        [default] dispinterface _EMApi;
        [default, source] dispinterface _EMApiEvents;
    };
};

My autoit code like:
 

; CZ EM API OLE Control
Local Const $CLSID_API = "{71BD42C4-EBD3-11D0-AB3A-444553540000}"

Local $CZEMApi=ObjCreate($CLSID_API)
If Not IsObj($CZEMApi) Then
    MsgBox(4096,"Failed to create APILib.Api object","You may need to run regsvr32 CZEMApi.ocx :error=" & Hex(@error,8))
    Exit
Else
    ;MsgBox(4096,"info","success")
EndIf

$Notify = ObjEvent($CZEMApi,"EMApiEvents_")

Func EMApiEvents_Notify($parameter,$reason)
   MsgBox(4096,"Notify", "Event catchall for " & $parameter & @TAB & $reason & @CR)
EndFunc

$CZEMApi.Caption = "for test"
MsgBox(4096,"caption",$CZEMApi.Caption)

Local $long = $CZEMApi.InitialiseRemoting()

Local $pVAR = ""
Local $result = $CZEMApi.Get("AP_MAG",Ptr($pVAR))

 

But issue is:

"G:\test.au3" (79) : ==> The requested action with this object has failed.:
Local $result = $CZEMApi.Get("AP_MAG",Ptr($pVAR))
Local $result = $CZEMApi^ ERROR

How to fixed this issue?

Share this post


Link to post
Share on other sites
ranber

I try the VBScript code is ok,

Dim Api1
Set Api1 = CreateObject("CZ.EMApiCtrl.1")
call Api1.InitialiseRemoting()
call Api1.Get("AP_MAG",Value)
call WScript.Echo("Magnification = " + CStr(Value))

 

Share this post


Link to post
Share on other sites
Jos
1 hour ago, ranber said:

I try the VBScript code is ok,

.. and what about this script?:

$Api1 = ObjCreate("CZ.EMApiCtrl.1")
$Api1.InitialiseRemoting()
$value=$Api1.Get("AP_MAG")
ConsoleWrite("Magnification = " & $value & @CRLF)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
ranber
14 hours ago, Jos said:

.. and what about this script?:

$Api1 = ObjCreate("CZ.EMApiCtrl.1")
$Api1.InitialiseRemoting()
$value=$Api1.Get("AP_MAG")
ConsoleWrite("Magnification = " & $value & @CRLF)

Jos

[id(1)] long Get(
                            BSTR lpszParam,
                            VARIANT* vValue);

  Get() Method has no [out,retval] attribute, I tried it get same failed.

Share this post


Link to post
Share on other sites
trancexx
Posted (edited)

And something obvious like this fails too?

Local $vVAR
Local $result = $CZEMApi.Get("AP_MAG", $vVAR)

 

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
ranber

I need Autoit Gui feature and more other features, and VBS can't supplied.

Share this post


Link to post
Share on other sites
ranber
16 minutes ago, trancexx said:

And something obvious like this fails too?

Local $vVAR
Local $result = $CZEMApi.Get("AP_MAG", $vVAR)

 

Thanks for your reply, I tried it get same error.

"G:\test.au3" (66) : ==> The requested action with this object has failed.:
Local $result = $CZEMApi.Get("AP_MAG",$pVAR)
Local $result = $CZEMApi^ ERROR

 

Share this post


Link to post
Share on other sites
trancexx

You need COM error handler initialized to get more info about the error. ObjEvent is the function for this too.

Post the details you get. This should work.

 


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
ranber
8 minutes ago, trancexx said:

You need COM error handler initialized to get more info about the error. ObjEvent is the function for this too.

Post the details you get. This should work.

 

$oMyError = ObjEvent("AutoIt.Error","_ErrFunc") ; Istall a custom error handler

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

Get COM error is:
 

test.au3 (82) : ==> COM Error intercepted !
    err.number is:         0x80020005
    err.windescription:    ÀàÐͲ»Æ¥Åä¡£

    err.description is:     
    err.source is:         
    err.helpfile is:     
    err.helpcontext is:     
    err.lastdllerror is:     0
    err.scriptline is:     82
    err.retcode is:     0x00000000

 

Share this post


Link to post
Share on other sites
mLipok
34 minutes ago, ranber said:

ÀàÐͲ»Æ¥Åä¡£

Could you translate this ?


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-09-20

Share this post


Link to post
Share on other sites
ranber
35 minutes ago, mLipok said:

Could you translate this ?

Type mismatch.

Share this post


Link to post
Share on other sites
mLipok
Posted (edited)

@trancexx I'm not sure .... but I think that I read somewhere that AutoIt not support for ByRef in ActiveX objects .
Am I right ?

Edit:  Second question:
Is it related to this user case ?

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-09-20

Share this post


Link to post
Share on other sites
mLipok
Posted (edited)

@ranber

Try this:

Local $vVAR = Binary(0)
Local $result = $CZEMApi.Get("AP_MAG", $vVAR)
Local $vVAR = Binary("")
Local $result = $CZEMApi.Get("AP_MAG", $vVAR)

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-09-20

Share this post


Link to post
Share on other sites
ranber
13 minutes ago, mLipok said:

@ranber

Try this:

Local $vVAR = Binary(0)
Local $result = $CZEMApi.Get("AP_MAG", $vVAR)
Local $vVAR = Binary("")
Local $result = $CZEMApi.Get("AP_MAG", $vVAR)

 

Thanks for your help, it also failed.

Share this post


Link to post
Share on other sites
ranber
34 minutes ago, mLipok said:

@trancexx I'm not sure .... but I think that I read somewhere that AutoIt not support for ByRef in ActiveX objects .
Am I right ?

Edit:  Second question:
Is it related to this user case ?

Maybe your right, the autoit no support for ByRef in ActiveX objects.

Share this post


Link to post
Share on other sites
trancexx
4 hours ago, mLipok said:

@trancexx I'm not sure .... but I think that I read somewhere that AutoIt not support for ByRef in ActiveX objects .
Am I right ?

Edit:  Second question:
Is it related to this user case ?

The code I wrote did support it. I don't know if something was changed afterwards.

However, I did leave small bug with initialization and intention to fix it during beta testing. Something that never happened. The bug was such that randomly execution would fail. But random isn't always.

  • Thanks 1

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
mLipok

This explains a lot.
Thanks.


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-09-20

Share this post


Link to post
Share on other sites
ranber
37 minutes ago, trancexx said:

The code I wrote did support it. I don't know if something was changed afterwards.

However, I did leave small bug with initialization and intention to fix it during beta testing. Something that never happened. The bug was such that randomly execution would fail. But random isn't always.

I tried all methods with parameter of VARIANT* ,float*, BSTR* also get same "Type mismatch"  error.

 

Share this post


Link to post
Share on other sites
mLipok

@ranber Could you post any link to some kind documentation for this object ?


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-09-20

Share this post


Link to post
Share on other sites
ranber
Posted (edited)
21 minutes ago, mLipok said:

@ranber Could you post any link to some kind documentation for this object ?

$oMyError = ObjEvent("AutoIt.Error","_ErrFunc") ; Istall a custom error handler

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

; CZ EM API OLE Control
Global $CZEMApi=ObjCreate("CZ.EMApiCtrl.1")
If Not IsObj($CZEMApi) Then
    MsgBox(4096,"Failed to create APILib.Api object","You may need to run regsvr32 CZEMApi.ocx :error=" & Hex(@error,8))
    Exit
EndIf

$Notify = ObjEvent($CZEMApi,"EMApiEvents_")

Func EMApiEvents_Notify($parameter,$reason)
   MsgBox(4096,"Notify", "Event catchall for " & $parameter & @TAB & $reason & @CR)
EndFunc

$CZEMApi.InitialiseRemoting()

Local $x,$y,$z,$r,$t,$m
Local $result = $CZEMApi.GetStagePosition($x,$y,$z,$r,$t,$m)

Get error:

>"D:\Program Files\AutoIt3\SciTE\..\AutoIt3.exe" "D:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "G:\test.au3" /UserParams    
+>21:02:19 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0   Keyboard:00000804  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64  Environment(Language:0804)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => D:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\ranber\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\ranber\AppData\Local\AutoIt v3\SciTE
>Running AU3Check (3.3.14.5)  from:D:\Program Files\AutoIt3  input:G:\test.au3
+>21:02:19 AU3Check ended.rc:0
>Running:(3.3.14.5):D:\Program Files\AutoIt3\autoit3.exe "G:\test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
test.au3 (75) : ==> COM Error intercepted !
    err.number is:         0x80020005
    err.windescription:    Type mismatch.

    err.description is:     
    err.source is:         
    err.helpfile is:     
    err.helpcontext is:     
    err.lastdllerror is:     0
    err.scriptline is:     75
    err.retcode is:     0x00000000

oIt3.e+>21:02:29 AutoIt3.exe ended.rc:0
+>21:02:29 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 11.69

 

Edited by ranber

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

×