Help with syntax to run Atem 2M/E Macro in C#

2 posts / 0 new
Last post
Offline

Location

Pompano Beach,
United States
Joined: 29/04/2016
Posts: 1
Help with syntax to run Atem 2M/E Macro in C#

I am programming a client in to run CasparCG. The client is in C# and I have most of it working. The only thing that I cannot get to work is the ATEM Library to run a macro stored in the ATEM2 M/E. Does anybody know the right syntax to execute a macro Here's the code for the client:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using CasparCGNETConnector;
using CasparCGClientForm;
using System.Runtime.InteropServices;
using BMDSwitcherAPI;

namespace CasparCGClientForm
{

//Code    

. . . . . 

//Code

        private void button2_Click(object sender, EventArgs e)
        {

            //Trying to run a macro on the ATEM 2 M/E. It does not work...
            IBMDSwitcherMacroControl playMacro;
            playMacro = new IBMDSwitcherMacroControl;
            playMacro(3);

        }

}
 

JohnBengston's picture
Offline

Location

London
United Kingdom
Joined: 14/01/2012
Posts: 2145
Ask yourself what this is

Ask yourself what this is doing??????

playMacro = new IBMDSwitcherMacroControl;

Answer: nothing it is totally meaningless. O.O.P-101 - You don't create instances of interfaces do you?

COM Programming is slightly different to base object orientated techniques, as it does domething called "reference counting", so with "a real programming language", you must call IUnknown's QueryInterface on a COM object in order to pickup a reference to it's other interfaces.

Learn what this does.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682521(v=vs.85).aspx

Just because C# and interop is doing it for you, doesn't mean you can forget what it is doing, and why. So I am very reluctant to say this, as it is simplifying it too much, but the IBMDSwitcherMacroControl interface is exposed by the Switcher Object, so all you actually need to do in c# is cast your switcher interface reference as a IBMDSwitcherMacroControl interface.

Because you excluded the code that establishes your Switcher Interface reference, I can't give you code to copy-paste, but it would look something like.

playMacro = (IBMDSwitcherMacroControl)switcherInterfaceReference;

Read this:

https://forum.blackmagicdesign.com/viewtopic.php?f=12&t=45033

or for more background on coding COM in C# read here:

https://forum.blackmagicdesign.com/viewtopic.php?f=12&t=41964&p=254640&hilit=c%23+aux#p254640

Good Luck with your project.