Jump to content
Sign in to follow this  
marcoauto

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

Share this post


Link to post
Share on other sites

Share this post


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

 

 

Share this post


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

Share this post


Link to post
Share on other sites

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

 

Saludos

Share this post


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

Share this post


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

 

Share this post


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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Colduction
      Hi AutoIt Scripters/Programmers. I have a question about MIME Tools for Notepad++:
      I've recently found a UDF about Base64 in forum, but they can't decode\encode correctly some emojis , other UTFs and etc. so i decided to use mimeTools.dll of Notepad++ or main site
      My problem is how to use this dll in AutoIt Language?

      I will be happy with your comments and answers❤ Thanks.
    • By FrancescoDiMuro
      Good morning Forums 
      In these days, I am working on a project that involved me to use some Windows APIs to obtain some information about Terminal Servers.
      I'm doing this using wtsapi32.dll in a VBA Project, but, the lack of knowledge about few things threated in the articles make this quite difficult to
      implement and understand at the same time.
      The most difficult thing I'm facing is "translating" C/C++ functions or struct in VBA when pointers are used, or pointers of pointers, and so on.
      Since VBA seems to not have a pointer type, to make those functions work I need to implement other functions taken from other DLLs, and this confuses me a lot.
      For example, starting from this code, I splitted all the functions and all the definitions to understand why they are there, and why I need to use them.
      At the end, I've found out that the code I was going to implement starting from the functions provided in the Microsoft Docs won't be ever be able to work without some supplementary functions which are not mentioned anywhere.
      So, I was wondering if someone would please point me out to a good and practical exaplanation about pointers (in general) or specifically for VBA, because I need to use them quite often in these days, and I'd like to understand what I am doing.
      Thanks in advance.

      Best Regards and Stay at home 🏡
       
    • By Colduction
      Hi AutoIt Programmers!

      I've seen a code that gives Name of Group by writing it's group's SID, but this one response very slower than Windows Command-Line WMIC
       
      Func _GetLocalGroupName($sSID = 'S-1-5-18') $objWMIService = ObjGet ("winmgmts:\\" & @ComputerName & "\root\cimv2") $colItems = $objWMIService.ExecQuery('SELECT Name FROM Win32_Group where SID="' & $sSID & '"') For $GroupNames in $colItems MsgBox (0,"",$GroupNames.Name) ExitLoop Next EndFunc I don't want call and use any third-party programs even CMD, i just want use from Windows API, netapi32.dll or AutoIt Functions (Standalone).
      Do you have any idea to improve speed/performance of this code? I'll happy of your comments
       
       
       
      ====================== SOLOUTION by @Subz ======================
       
    • By zuladabef
      All my scripts were working fine and now I am getting this error.  How do I resolve it?  Which folder(s) do the DLLs need to be in?
      ! Dll not found or Call Dll error !  
×
×
  • Create New...