问题 Blackmagic Videohub

努马

新成员
已加入
2018年8月31日
留言内容
3
编程经验
Beginner
嗨伙计,

我正在尝试用C#编写Blackmagic Videohub应用程序,但是不幸的是BMD没有为C#提供任何示例项目。
请有人帮我了解C#中的VideoHub福彩12选5走势图和addref

我的代码是:
private Videohub.HubMonitor m_hubMonitor;
public Form1()
{
    InitializeComponent();
}
IVideohubDiscovery videoHubDiscovery;
public static IVideohub m_hub;
static IVideohubState m_state;
private void button1_Click(object sender, EventArgs e)
{
    videoHubDiscovery = new CVideohubDiscovery();
    try
    {
        videoHubDiscovery.ConnectTo(TBserver.Text, 10000, out m_hub);
    }
    catch(COMException ex)
    {
        if (ex.HResult == -2147467259)
            MessageBox.Show("Connection Timeout");
        return;
    }
    m_hub.GetState(out m_state);
    uint index = 0;
    _BMDVideohubHardwareState hardware = new _BMDVideohubHardwareState();
    System.Diagnostics.Debug.WriteLine("--- Video input ports\n");
    while (index <= 40 - 1)
    {
        m_state.GetLabel(_BMDVideohubPortType.BMDVideohubVideoInputPort, index, out string label);
        m_state.GetHardware(_BMDVideohubPortType.BMDVideohubVideoInputPort, index, out hardware);
        string bstrLabel = label;
        System.Diagnostics.Debug.WriteLine("  \n " + index + " " + hardware.ToString() + " " + bstrLabel);
        index++;
    }
    //m_hubMonitor = new Videohub.HubMonitor(m_hub);
    //m_hub.AddVideohubCallback(m_hubMonitor);
}

我正在获取这样的输入端口,但是当我尝试通过调用回调获取输入端口时,我得到E_NOINTERFACE错误,甚至尝试从另一种方法获取输入端口,我也得到了相同的E_NOInterface错误

回调错误行是:
public HubMonitor(IVideohub hub)
{
    m_hub = hub;
}

void IVideohubCallback.StateChanged()
{
    if (m_state == null)
    {
        m_hub.GetState(out m_state); //Getting Error Here NOINTERFACE
        DumpState(m_state);
    }
    else
    {
        m_hub.GetState(out m_state);
        DumpState(m_state);
    }
}
等待帮助

谢谢并恭祝安康,
努马安
 
由主持人最后编辑:

努马

新成员
已加入
2018年8月31日
留言内容
3
编程经验
Beginner
感谢您的回复..赞赏!

黑魔法用示例提供C ++中的SDK 关联
根据sdk
福彩12选5走势图参考每个对象福彩12选5走势图都是IUnknown福彩12选5走势图的子类。IUnknownInterfaceEach每个API福彩12选5走势图都是标准COM基类IUnknown的子类。 IUnknownobject福彩12选5走势图提供引用计数和通过福彩12选5走势图ID查找相关福彩12选5走势图的功能。福彩12选5走势图ID机制允许在不影响现有应用程序的情况下将福彩12选5走势图添加到API。
QueryInterface提供对对象支持的子福彩12选5走势图的访问。
AddRef增加对象的引用计数。
释放减少对象的引用计数。删除最终引用后,将释放对象。

IUnknown :: QueryInterface方法QueryInterface方法查找对象福彩12选5走势图的相关福彩12选5走势图。
语法HRESULT QueryInterface(REFIID id,void ** outputInterface);
IUnknown :: AddRef方法AddRef方法增加对象福彩12选5走势图的引用计数。
语法ULONG AddRef();
IUnknown :: Release方法Release方法减少对象福彩12选5走势图的引用计数。从对象中删除最后引用后,该对象将被销毁。
语法ULONG Release();

C ++中的示例代码:
/* -LICENSE-START-** Copyright (c) 2009 Blackmagic Design
**
** Permission is hereby granted, free of charge, to any person or organization
** obtaining a copy of the software and accompanying documentation covered by
** this license (the "Software") to use, reproduce, display, distribute,
** execute, and transmit the Software, and to prepare derivative works of the
** Software, and to permit third-parties to whom the Software is furnished to
** do so, all subject to the following:
** 
** The copyright notices in the Software and this entire statement, including
** the above license grant, this restriction and the following disclaimer,
** must be included in all copies of the Software, in whole or in part, and
** all derivative works of the Software, unless such copies or derivative
** works are solely in the form of machine-executable object code generated by
** a source language processor.
** 
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
** DEALINGS IN THE SOFTWARE.
** -LICENSE-END-
*/


#include <comutil.h>                // for _bstr_t
#include <iostream>
#include <objbase.h>                // Necessary for COM
#include <stdio.h>
#include <tchar.h>


#include "FormattedOutput.h"
#include "Menu.h"
#include "VideohubAPI_h.h"




class MyVideohubCallback : public IVideohubCallback
{
    int                    m_refCount;
    IVideohubState *    m_state;
    IVideohub *            m_hub;
    
public:
    
    MyVideohubCallback(IVideohub *hub) : m_hub(hub), m_refCount(0), m_state(NULL) {}
    ~MyVideohubCallback() 
    {
        if (m_state!=NULL)
            m_state->Release();
    }
    
    HRESULT STDMETHODCALLTYPE StateChanged()
    {
        if (m_state == NULL)
        {
            // it is the first we are called, get the IvideohubAttributes interface
            // and print some details about the Videohub device
            printDeviceInfo();


            // we havent got an IVideohubState yet, get one
            if(m_hub->GetState(&m_state)==S_OK)
            {
                dumpState(m_state);
            }
        }
        else
        {
            // we already have an IVideohubState, update it
            // and get an iterator over the changes
            IVideohubStateChangeIterator *iter;
            
            if (m_state->UpdateState(&iter)==S_OK)
            {
                dumpChanges(m_state, iter);
                iter->Release();
            }
        }


        // re-print the user menu
        printMenu();


        return S_OK;
    }
    
    HRESULT STDMETHODCALLTYPE DeviceDisconnected()
    {
        printf_s("******\tVideohub DISCONNECTED\t******\n");
        return S_OK;
    }
    
    HRESULT STDMETHODCALLTYPE DeviceReconnected()
    {
        printf_s("******\tVideohub RECONNECTED\t******\n");
        return S_OK;
    }


    HRESULT STDMETHODCALLTYPE NewDeviceConnected()
    {
        return S_OK;
    }
    
    // IUnknown interface methods
    HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv)
    {
        HRESULT            result = E_NOINTERFACE;


        *ppv = NULL;


        if (iid == IID_IUnknown)
        {
            *ppv = this;
            AddRef();
            result = S_OK;
        }
        else if (iid == IID_IVideohubCallback)
        {
            *ppv = (IVideohubCallback*)this;
            AddRef();
            result = S_OK;
        }
        
        return result;
    }
    
    ULONG STDMETHODCALLTYPE AddRef(void)
    {
        m_hub->AddRef();
        return InterlockedIncrement((LONG*)&m_refCount);
    }
    
    ULONG STDMETHODCALLTYPE Release(void)
    {
        long        newRefValue;


        m_hub->Release();
        newRefValue = InterlockedDecrement((LONG*)&m_refCount);
        if (newRefValue == 0)
        {
            delete this;
        }
        
        return newRefValue;    
    }


    void printDeviceInfo()
    {
        IVideohubAttributes *attributes = NULL;
        
        if (m_hub->QueryInterface(IID_IVideohubAttributes, (void **) &attributes)==S_OK)
        {
            // print some info about the device
            dumpVideohubInfo(attributes);
            
            // release the interface
            attributes->Release();
        }
        else
        {
            printf("Error obtaining the Attributes interface\n");
        }
    }
};


int _tmain(int argc, _TCHAR* argv[])
{
    HRESULT                    result;
    IVideohubDiscovery        *videoHubDiscovery = NULL;
    IVideohub                *videohub;
    MyVideohubCallback        *cb;




    // check the arguments
    if (argc!=2)
    {
        printf_s("usage: DeviceState <videohub device address>");
        return 1;
    }


    // initialise the device address
    _bstr_t deviceAddress(argv[1]);
    
    // Initialize COM on this thread
    result = CoInitialize(NULL);
    if (FAILED(result))
    {
        printf_s("Initialization of COM failed - result = %08x.\n", result);
        return 1;
    }


    // Create an IVideohubDiscovery object
    result = CoCreateInstance(CLSID_CVideohubDiscovery, NULL, CLSCTX_ALL, IID_IVideohubDiscovery, (void**)&videoHubDiscovery);
    if (FAILED(result))
    {
        printf_s("A Videohub Discovery object could not be created.\n");
        goto bail;
    }


    // get an IVideohub object for our device address
    if(videoHubDiscovery->ConnectTo(deviceAddress, 10000, &videohub) == S_OK)
    {
        // instantiate an IVideohubCallback object to receive state change notifications
        cb = new MyVideohubCallback(videohub);
        cb->AddRef();


        // register the callback object
        videohub->AddVideohubCallback(cb);


        // wait for user input
        // this function returns when the user selects the Quit option
        waitForUserInput(videohub);


        // remove the callback object
        videohub->RemoveVideohubCallback(cb);


        // release the callback object
        cb->Release();


        // release the IVideohub object
        videohub->Release();
    }
    else
    {
        printf_s("An IVideohub object could not be created for the given address\n");
    }


    // release the VideohubDiscovery object
    videoHubDiscovery->Release();


bail:
    // Uninitalize COM on this thread
    CoUninitialize();


    return 0;
}


当我尝试在C#中使用SDK时,出现了E_NOINTERFACE错误,正如我在第一篇文章中提到的那样。我想我每次都要查询界面,但是我不知道如何
 
Last edited:

跳伞

工作人员
已加入
2019年4月6日
留言内容
2,536
地点
弗吉尼亚州切萨皮克
编程经验
10+
我希望他能回应。自2018年以来他一直没有登录。

无论如何,您甚至看过他发表的原始帖子吗?它在C#中。
 
最佳 底部