Jump to content
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

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

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

  • Similar Content

    • By matwachich
      Hi guys!
      A pretty simple UDF to convert HTML to PDF using wkHTMLtoPDF.
      It uses the C API of the tool (DLL), so no external process, no ActiveX or COM sh*t.
      See the example, and the documentation of wkHTMLtoPDF.
      Cheers
      https://github.com/matwachich/wkhtmltopdf-au3
    • By jamesbowers
      Hi guys! I have a problem that i hope you give me an advice to solve it. I have writing this code and it doesn't run cuz its a problem.
      C2562 'Draw':'void' function returning a vaue.....
      I dont know what to correct.
       

    • By Skysnake
      This is relevant
      From here https://stackoverflow.com/questions/3454315/is-it-possible-to-pin-a-dll-in-memory-to-prevent-unloading
      I use several UDFs on the Forum to do various things.  Those UDFs work very well.
      Effectively the UDFs are DLL wrappers, that make it possible to access DLL functions easily without the long hard slog of DLLCall() every time.
      However, I have now run into the issue that multiple UDF DLLCalls are slow. Not mind numbingly slow, but slow enough to become noticeable with a large of repeated function calls.
      So I was wondering, is it possible to "load a DLL into memory" and leave it there for the duration of my script's lifetime, avoid repeated DLL on-disk reads with a persistent in memory DLL?
      From Microsoft
      https://docs.microsoft.com/en-us/windows/desktop/dlls/about-dynamic-link-libraries
      Looks like what I want to do is: load-time dynamic linking,
      So next question, (a) how do I do this with AutoIt (b) How would this impact on standard AutoIt type DLL calls?
       
      The point is speed.  Is there a different approach?
      Or am I barking up the wrong tree?
      Skysnake
    • By orbs
      for a savvy c++ developer, how hard would it be to compile this into a standalone Win32 console executable?
      i have almost no experience with c++ (and i have no need for any more, since i have AutoIt for pretty much all my requirements). i can compile a simple "hello world" executable (and even embed the mfc dll for backward compatibility). but i am quite interested with that project. your opinion?
       
      P.S. this relates to AutoIt quite simply - once (if and when) i have that project as a standalone executable, i have a GUI made with AutoIt to execute it, then post-process and display the output.
       
    • By bladem2003
      Hello,
      i need help to translate the c code to autoit .
      I don't understand the callback function.
       
      #include <windows.h> #include <stdio.h> // native IR Data by PAnsiChar typedef void CALLBACK CallBackPAnsiChar(char*, char*, char*, char*); typedef int (__stdcall *impInitPAnsiChar)(CallBackPAnsiChar); CALLBACK MyCallBackPAnsiChar(char* Protocol, char* Address, char* Command, char* Flags) { printf("\nIR Data received: Protocol: %s, Address: 0x%s, Command: 0x%s, Flags: 0x%s", Protocol, Address, Command, Flags); fflush(stdout); } int main(int argc, char **argv) { impInitPAnsiChar InitPAnsiChar = NULL; // Load DLL file HINSTANCE hinstLib = LoadLibrary(TEXT("USB_IR_Remote_Receiver.dll")); if (hinstLib == NULL) { printf("\nERROR: unable to load DLL\n"); return 1; } // Get function pointer InitPAnsiChar InitPAnsiChar = (impInitPAnsiChar)GetProcAddress(hinstLib, "InitPAnsiChar"); if (InitPAnsiChar == NULL) { printf("\nERROR: unable to find DLL function\n"); FreeLibrary(hinstLib); return 1; } if (InitPAnsiChar(*MyCallBackPAnsiChar)) { printf("\nInit DLL with InitPAnsiChar successfull"); } else { // Unload DLL file FreeLibrary(hinstLib); return 0; } while(1) { } //return 0; }  
×
×
  • Create New...