Jump to content

Convert from C++ to Autoit for ATEM Mixer


Recommended Posts

Ciao

I would like to control an ATEM Video Mixer from autoit. I downloaded his SDK which is written in c ++ and I found the sequences to interface, but I was not able to convert the script to self.

The instructions say to follow this sequence:

Quote
Switcher Configuration and Transitions
An application for controlling a switcher may perform the following steps:
‚ Use IBMDSwitcherDiscovery::ConnectTo to connect to a switcher device and obtain
an IBMDSwitcher object interface
‚ Use IBMDSwitcher::CreateIterator to get an IBMDSwitcherInputIterator
object interface
‚ For each IBMDSwitcherInput returned by IBMDSwitcherInputIterator::Next retrieve
the input’s unique Id using IBMDSwitcherInput::GetInputId and retrieve other properties
of the input, such as the input’s name, using IBMDSwitcherInput::GetString or
IBMDSwitcherInput::GetInt
‚ Use IBMDSwitcher::CreateIterator to get an IBMDSwitcherMixEffectBlockIterator
object interface
‚ Obtain an IBMDSwitcherMixEffectBlock object interface using
IBMDSwitcherMixEffectBlockIterator::Next
‚ Use IBMDSwitcherMixEffectBlock::SetInt to configure the Program and
Preview inputs to the mix effect block by assigning the input Ids returned by
IBMDSwitcherInput::GetInputId
‚ Perform a transition between Program and Preview inputs by calling
IBMDSwitcherMixEffectBlock::PerformTransition
‚ Install a callback using IBMDSwitcherMixEffectBlock::AddCallback and receive
IBMDSwitcherMixEffectBlockCallback::PropertyChanged callbacks to determine
progress through the transition and when the transition is complete

and to connectTo with C++ is:

string address = "192.168.1.240";
_BMDSwitcherConnectToFailure failureReason = 0;
IBMDSwitcher switcher = null;
var discovery = new CBMDSwitcherDiscovery();
discovery.ConnectTo(address, out switcher, out failureReason);

From Blackmagic SDK:

IBMDSwitcherDiscovery::ConnectTo method
The ConnectTo method connects to the specified switcher and returns an IBMDSwitcher object interface for the switcher.

Syntax
HRESULT ConnectTo (string deviceAddress, IBMDSwitcher** switcherDevice, BMDSwitcherConnectToFailure* failReason);
Parameters:
deviceAddress in Network hostname or IP address of switcher to connect to.
switcherDevice out IBMDSwitcher object interface for the connected switcher.
failReason out Reason for connection failure as a BMDSwitcherConnectToFailure value.

So, I have I tried these solutions but with non success:

$DllName =@ScriptDir&"\BMDSwitcherAPI.dll"
$result = DllCall($DllName, "none", "IBMDSwitcherDiscovery::ConnectTo" & @CRLF)
ConsoleWrite("DLLCall Result: " & $result & @CRLF)

and I have tried also create an Object (That I think is the best way solution):

#include <MsgBoxConstants.au3>

$oSwitcher=ObjCreate("IBMDSwitcher")
If IsObj($oSwitcher) Then
    MsgBox(64, "", "Object $oSwitcher created successfully")
EndIf
$oAtem=ObjCreate("IBMDSwitcherDiscovery")
If IsObj($oAtem) Then
    MsgBox(64, "", "Object $oAtem created successfully")
EndIf
$failureReason =ObjCreate("_BMDSwitcherConnectToFailure")
If IsObj($failureReason) Then
    MsgBox(64, "", "Object $failureReason created successfully")
EndIf
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler
Global $errore,$oSwitcher1
$oAtem.ConnectTo("192.168.1.36",$oSwitcher,$failureReason);
; This is the custom error handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "Windescription is: " & $oMyError.windescription & @CRLF & _
            "Source is: " & $oMyError.source & @CRLF & _
            "Description is: " & $oMyError.description & @CRLF & _
            "Helpfile is: " & $oMyError.helpfile & @CRLF & _
            "Helpcontext is: " & $oMyError.helpcontext & @CRLF & _
            "Lastdllerror is: " & $oMyError.lastdllerror & @CRLF & _
            "Scriptline is: " & $oMyError.scriptline)
EndFunc   ;==>MyErrFunc

But the result is:

We intercepted a COM Error !
Number is: 000000A9
Windescription is: Variable must be of type 'Object'.
Source is: 
Description is: 
Helpfile is: 
Helpcontext is: 
Lastdllerror is: 0
Scriptline is: 17

The BMDSwitcherAPI.dll is registered in system. Can someone help me?

Grazie

Marco

Link to post
Share on other sites

Hello. You need to get the basic about AutoIt DllCall Function. You're walking blind. You also need to get the basic about C++ Implement this. I really have not to much free time to look deeply in the doc file. You need to make sure this SDK registers a COM Visible Object otherwise You can't use ObjCreate. If You can't you probably need to use ObjCreateInterface to handle this. let's try this script. I don't know the ProgID (if It shows one) So I'm using the CLSID to create the object. (not sure if it will work). If It does not. Good look with ObjCreateInterface or probably direct dll calls of which I'm not sure if it exposes the functions.

 

Script: (sorry I'm unable to load sintaxis highlighting)

Global Const $sCLSID_CBMDSwitcherDiscovery='{F2DC5149-9599-47E4-84B9-054C78A1A46D}'
Local $oObject=ObjCreate($sCLSID_CBMDSwitcherDiscovery)
ConsoleWrite('IsObj($oObject): ' & IsObj($oObject) & @CRLF)

 

Saludos

 

 

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

Hello. You need to get the basic about AutoIt DllCall Function. You're walking blind. You also need to get the basic about C++ Implement this. I really have not to much free time to look deeply in the doc file. You need to make sure this SDK registers a COM Visible Object otherwise You can't use ObjCreate.

Yes, the problem is I don't know how to understand if is a COM Visible method.

the result of

Global Const $sCLSID_CBMDSwitcherDiscovery='{F2DC5149-9599-47E4-84B9-054C78A1A46D}'
Local $oObject=ObjCreate($sCLSID_CBMDSwitcherDiscovery)
ConsoleWrite('IsObj($oObject): ' & IsObj($oObject) & @CRLF)

in console is:

IsObj($oObject): 0

I'll try with ObjCreateInterface. I'll study the sintax.

My problem is that I do not have the knowledge of c ++ to understand how it works. I'll try

Thankyou for your time!

Marco

Link to post
Share on other sites

Could you provide me the BMDSwitcherAPI.dll to do some tests.

 

Saludos

Link to post
Share on other sites

Here a simple example for create a CBMDSwitcherDiscovery Interface.

Global Const $sCLSID_CBMDSwitcherDiscovery = "{F2DC5149-9599-47E4-84B9-054C78A1A46D}"
Global Const $sIID_IBMDSwitcherDiscovery = "{A676047A-D3A4-44B1-B8B5-31D7289D266A}"
Global Const $sTag_IBMDSwitcherDiscovery = "ConnectTo hresult(bstr;ptr*;int*);"


Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $oCBMDSwitcherDiscovery = ObjCreateInterface($sCLSID_CBMDSwitcherDiscovery, $sIID_IBMDSwitcherDiscovery, $sTag_IBMDSwitcherDiscovery)
ConsoleWrite("IsObj($oCBMDSwitcherDiscovery): " & IsObj($oCBMDSwitcherDiscovery) & @CRLF)

Local $sDeviceAddress = "192.168.1.240"
Local $pIBMDSwitcher = 0
Local $iConnectToFailure = 0
$oCBMDSwitcherDiscovery.ConnectTo($sDeviceAddress, $pIBMDSwitcher, $iConnectToFailure)
ConsoleWrite("$pIBMDSwitcher: " & $pIBMDSwitcher & @CRLF)
ConsoleWrite("$iConnectToFailure: " & $iConnectToFailure & @CRLF)


; 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

on success you'll need to casting $pIBMDSwitcher pointer to an Interface IBMDSwitcher using ObjectCreateInterface

 

Saludos

Link to post
Share on other sites

ciao,

Hi, I tried to do what you told me, but I can not understand the syntax I have to use. I'm trying to study how c ++ works but it's very different from autoit and so I have a lot of difficulties
For the moment I did only this with success: $oIBMDSwitcher.GetProductName($nome) 

 

Global Const $sCLSID_CBMDSwitcherDiscovery = "{F2DC5149-9599-47E4-84B9-054C78A1A46D}"
Global Const $sIID_IBMDSwitcherDiscovery = "{A676047A-D3A4-44B1-B8B5-31D7289D266A}"
Global Const $sTag_IBMDSwitcherDiscovery = "ConnectTo hresult(bstr;ptr*;int*);"
Global Const $sIID_IBMDSwitcher = "{3D480E2F-3CF4-474B-92E7-B7907EE83B41}"
Global Const $sTag_IBMDSwitcher = "ConnectTo hresult(bstr;ptr*;int*);"
Global Const $sTag_IBMDSwitcher_CreateIterator = "CreateIterator hresult(ptr*;int*);"

Global Const $sIID_IBMDSwitcherMixEffectBlockIterator = "{930BDE3B-4A78-43D0-8FD3-6E82ABA0E117}"
Global Const $sTag_IBMDSwitcherMixEffectBlockIterator = "Next hresult(int*);"

Global Const $sIID_IBMDSwitcherMixEffectBlock = "{11974D55-45E0-49D8-AE06-EEF4D5F81DF6}"
Global Const $sTag_IBMDSwitcherMixEffectBlock = "CreateIterator hresult(REFIID, LPVOID*);"

Global Const $sIID_IBMDSwitcherInputIterator = "{275E9888-2F65-4B2E-9434-1937A72B9EC4}"
Global Const $sTag_IBMDSwitcherInputIterator = " GetById hresult (int,int*);"


Global Const $sTag_IBMDSwitcher_GetProductName  = "GetProductName  hresult(bstr*);"

Global Const $sTag_IBMDSwitcher_Creator = "CreateIterator hresult(lpvoid*);"

Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $oCBMDSwitcherDiscovery = ObjCreateInterface($sCLSID_CBMDSwitcherDiscovery, $sIID_IBMDSwitcherDiscovery, $sTag_IBMDSwitcherDiscovery)
ConsoleWrite("IsObj($oCBMDSwitcherDiscovery): " & IsObj($oCBMDSwitcherDiscovery) & @CRLF)
$sFileWithDefinition = ObjName($oCBMDSwitcherDiscovery)
ConsoleWrite($sFileWithDefinition & @CRLF)

Local $sDeviceAddress = "192.168.1.37"
Local $pIBMDSwitcher = 0
Local $iConnectToFailure = 0
$oCBMDSwitcherDiscovery.ConnectTo($sDeviceAddress, $pIBMDSwitcher, $iConnectToFailure)
ConsoleWrite("$pIBMDSwitcher: " & $pIBMDSwitcher & @CRLF)
ConsoleWrite("$iConnectToFailure: " & $iConnectToFailure & @CRLF)
ConsoleWrite("-------" & @CRLF)
;~ Output console:
;~ IsObj($oCBMDSwitcherDiscovery): 1
;~ InterfaceDispatch
;~ $pIBMDSwitcher: 72569844
;~ $iConnectToFailure: 0
;~ -------

local $iterator,$nome
Local $oIBMDSwitcher = ObjCreateInterface($pIBMDSwitcher,$sIID_IBMDSwitcher,$sTag_IBMDSwitcher_GetProductName);$sTag_IBMDSwitcher_Creator)
ConsoleWrite("IsObj($oIBMDSwitcher): " & IsObj($oIBMDSwitcher) & @CRLF)
$sFileWithDefinition = ObjName($oIBMDSwitcher)
ConsoleWrite($sFileWithDefinition & @CRLF)
ConsoleWrite("-------" & @CRLF)
;~ Output console:
;~ IsObj($oIBMDSwitcher): 1
;~ InterfaceDispatch
;~ -------

$oIBMDSwitcher.GetProductName($nome)
ConsoleWrite("$oIBMDSwitcher.GetProductName: " & $nome & @CRLF)
ConsoleWrite("-------" & @CRLF)
;~ Output console:
;~ $oIBMDSwitcher.GetProductName: ATEM 1 M/E Production Switcher
;~ -------

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

I'd like to set a preview input and after do a cut transition

From a c++ script:

result = mSwitcher->CreateIterator((IID_IBMDSwitcherInputIterator, (void**)&inputIterator);

but I can't understand how to obtain  (void**)&iterator and how to declare it

from SDK is

IBMDSwitcher::CreateIterator method
HRESULT CreateIterator (REFIID iid, LPVOID* ppv);
iid [in] = Iterator Interface ID to create an iterator for
ppv [in] = Pointer to return interface object.
result = mSwitcher->CreateIterator(IID_IBMDSwitcherInputIterator, (void**)&inputIterator);

I tried with

$return  = $oIBMDSwitcher.CreateIterator($sIID_IBMDSwitcherInputIterator,$pIBMDSwitcher)
ConsoleWrite("$oIBMDSwitcher.CreateIterator: " & $return & @CRLF)
ConsoleWrite("-------" & @CRLF)
;~ Output console:
;~ atem.au3 (109) : ==> COM Error intercepted !
;~  err.number is:      0x80020006
;~  err.windescription: Nome sconosciuto.

;~  err.description is:
;~  err.source is:
;~  err.helpfile is:
;~  err.helpcontext is:
;~  err.lastdllerror is:    0
;~  err.scriptline is:  109
;~  err.retcode is:     0x00000000

but is wrong, of course!

from SDK I need to:

IBMDSwitcher::CreateIterator to get an IBMDSwitcherInputIterator object interface

For each IBMDSwitcherInput returned by IBMDSwitcherInputIterator::Next retrieve the input’s unique Id using IBMDSwitcherInput::GetInputId and retrieve other properties of the input, such as the input’s name, using IBMDSwitcherInput::GetString or IBMDSwitcherInput::GetInt

Use IBMDSwitcher::CreateIterator to get an IBMDSwitcherMixEffectBlockIterator object interface

Obtain an IBMDSwitcherMixEffectBlock object interface using IBMDSwitcherMixEffectBlockIterator::Next

Use IBMDSwitcherMixEffectBlock::SetInt to configure the Program and Preview inputs to the mix effect block by assigning the input Ids returned by IBMDSwitcherInput::GetInputId

Perform a transition between Program and Preview inputs by calling IBMDSwitcherMixEffectBlock::PerformTransition

Install a callback using IBMDSwitcherMixEffectBlock::AddCallback and receive IBMDSwitcherMixEffectBlockCallback::PropertyChanged callbacks to determine progress through the transition and when the transition is complete

 

Thanks

marco

 

Link to post
Share on other sites

Hello. I think the best and easy alternative for you is use .NET I think SDK has some C# examples, because convert this to AutoIt is a little hard if you dont have at least basic knowledge of C++ / AutoIt. 

 

 

Saludos

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By genius257
      I've made a library, based on AutoItObject UDF with the goal of implementing getter and setter functionality and make it possible to define new object properties in as few steps as possible.
      Thank you to @trancexx for getting me on the right track, and all users in Hooking into the IDispatch interface for the code to get me going.
      If I've forgotten to add credit, please let me know
      Example:
      #include "AutoItObject_Internal.au3" $myCar = IDispatch() $myCar.make = 'Ford' $myCar.model = 'Mustang' $myCar.year = 1969 $myCar.__defineGetter('DisplayCar', DisplayCar) Func DisplayCar($oThis) Return 'A Beautiful ' & $oThis.parent.year & ' ' & $oThis.parent.make & ' ' & $oThis.parent.model EndFunc MsgBox(0, "", $myCar.DisplayCar) More examples: https://github.com/genius257/AutoItObject-Internal/tree/master/Examples
      Version: 4.0.1
      AutoItObject_Internal.au3
      Documentation
      Edit2 (19th March 2017):
      First of all, sorry about the lack of updates on this project. I always start too many projects and end up ignoring old projects, if I run into problems ^^'.
      So I've started moving my AutoIt scripts to GitHub. I will still post the most recent script version here.
    • By sylremo
      I tried to implement the code in this topic:
      Firstly, i have no idea how these lines of code work but meanwhile i noticed that:
      ; Everytime autoit wants to call a method, get or set a property in a object it needs to go to ; IDispatch::GetIDsFromNames. This is our version of that function, note that by defining this ourselves ; we can fool autoit to believe that the object supports a lot of different properties/methods. Func __IDispatch_GetIDsFromNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId) ... EndFunc The problem is i ran into is that some object calls didn't go through IDispatch::GetIDsFromNames.
      Here is the code to replicate what i'm mentioning:
      I followed the example in the topic and tried to do the same thing with method .Documents (line 193) and .Open (line 194) but didn't get the same result because .Documents was being passed through __IDispatch_GetIDsFromNames while .Open didn't.
      $Au3_CallByName = 'Documents' Local $oDoc = $oAppl.Au3_CallByName $Au3_CallByName = 'Open' $oDoc = $oDoc.Au3_CallByName($sFilePath, $bConfirmConversions, $bReadOnly, $bAddToRecentFiles, $sOpenPassword, "", $bRevert, $sWritePassword, "", $iFormat) Console outputs:
      ==> The requested action with this object has failed.: $oDoc = $oDoc.Au3_CallByName($sFilePath, $bConfirmConversions, $bReadOnly, $bAddToRecentFiles, $sOpenPassword, "", $bRevert, $sWritePassword, "", $iFormat) $oDoc = $oDoc^ ERROR Is there any workarounds to solve this?

      Thank you!
    • By DevMode
      welcome
      I need help dealing with a C++ DLL
      Specify that I need help with how to use this function
      struct libusb_device; typedef struct libusb_context libusb_context; ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,libusb_device ***list); My problem is how to deal with "libusb_device ***list"
      my code 
      $libusb_device = DllStructCreate("PTR") Func libusb_init() $Var = DllCall($libusb0, "ptr", "libusb_init",'ptr',$_libusb_device_handle_Ptr) If @error Then Return False Return $Var[1] EndFunc Func libusb_get_device_list() MsgBox(0,VarGetType($_libusb_device_handle_Ptr),$_libusb_device_handle_Ptr) $Var = DllCall($libusb0, "int", "libusb_get_device_list","ptr",$_libusb_device_handle_Ptr,"ptr*",POINTER(POINTER($libusb_device))) $Error = @error If $Error Then Return False MsgBox(0,VarGetType($Var),$Error&@CRLF&$Var) _ArrayDisplay($Var) Return $Var[1] EndFunc  
      Thank you
      iLibUSB.dll iLibUSB_32.dll libusb.h
    • By bobflumox
      Hi all,
      My programming knowledge is very basic.
      I have an old script that creates shares and assign permissions. It normally registers SetAcl.ocx if necessary and creates an object to assign permissions.
      The command that registers SetAcl was apparently working fine under Windows 7 but is not working under Windows 10.
      RunWait("regsvr32.exe path\to\setacl.ocx /s", "", @SW_HIDE) As I'm logged in as admin, I changed this command to :
      RunAsWait(@UserName, "", "", 0, "regsvr32.exe path\to\setacl.ocx /s", "", @SW_HIDE) It seems to terminate correctly but the script still doesn't work as expected.
      To check that, I've created that small script :
      Local $objSetAcl = ObjCreate("SETACL.SetACLCtrl.1") If IsObj($objSetAcl) Then ConsoleWrite("Object successfully created." & @CRLF) Else ConsoleWrite("Object not created. Registering SetAcl.ocx" & @CRLF) Local $result = RunAsWait(@UserName, "", "", 0, "regsvr32.exe path\to\setacl.ocx /s", "", @SW_HIDE); Use of my admin username to elevate CMD ConsoleWrite("Return code : " & $result & @CRLF) ConsoleWrite("Creating object" & @CRLF) $objSetAcl = ObjCreate("SETACL.SetACLCtrl.1") If IsObj($objSetAcl) Then ConsoleWrite("Object successfully created." & @CRLF) Else ConsoleWrite("Object creation failed." & @CRLF) EndIf EndIf It tries to register SetAcl.ocx, return code 0 seems to be fine but still can't use SetAcl.
      But if I go to CMD as admin, run the regsvr32 command and restart my script, it can create the object without issue.
      I know my poor knowledge makes me miss something. Anyone can help me figure this out ?
    • By nacerbaaziz
      hello autoit team
      please
      i tried to create a SPVoice object 
      when i create the object and tried to use this function SetAlertBoundary
      it gave me an error
      please where is the problem?
      here is the code
      local $o_Sapi_OBJ = ObjCreate("SAPI.SpVoice") if IsObj($o_Sapi_OBJ) then $o_Sapi_OBJ.SetAlertBoundary("SPEI_PHONEME") endIf note i got the function name from microsoft web site
       
      https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms719784(v=vs.85)
      i have windows10
×
×
  • Create New...