Jump to content

Recommended Posts

Posted

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?

Posted

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))

 

  • Developers
Posted
  On 5/3/2018 at 12:51 PM, ranber said:

I try the VBScript code is ok,

Expand  

.. and what about this script?:

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

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted
  On 5/3/2018 at 2:09 PM, Jos said:

.. and what about this script?:

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

Jos

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

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

Posted
  On 5/4/2018 at 5:18 AM, trancexx said:

And something obvious like this fails too?

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

 

Expand  

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

 

Posted

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

Posted
  On 5/4/2018 at 5:56 AM, 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.

 

Expand  
$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

 

Posted
  On 5/4/2018 at 6:06 AM, ranber said:

ÀàÐͲ»Æ¥Åä¡£

Expand  

Could you translate this ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 5/4/2018 at 7:38 AM, 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 ?

Expand  

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

Posted
  On 5/4/2018 at 7:38 AM, 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 ?

Expand  

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.

♡♡♡

.

eMyvnE

Posted

This explains a lot.
Thanks.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 5/4/2018 at 12:09 PM, 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.

Expand  

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

 

Posted

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

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 5/4/2018 at 12:59 PM, mLipok said:

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

Expand  
$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

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
×
×
  • Create New...