我最近得到了一个 .NET 项目来编译,而无需从以前的开发人员那里得到进一步的知识,并且在修复了大多数错误之后(我使用的是 Visual Studio 2017,项目的先前版本是这样的)
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
我仍然收到错误
行抑制状态错误 LNK2022 元数据操作失败(8013118D):重复类型中的布局信息不一致(ChooseDeviceParam):(0x02000273)。
这是声明“ChooseDeviceParam”的部分代码(VideoSourceList.cpp)
struct ChooseDeviceParam
{
IMFActivate **ppDevices = nullptr; // Array of IMFActivate pointers.
UINT32 count = 0; // Number of elements in the array.
~ChooseDeviceParam()
{
if (ppDevices != nullptr)
{
for (UINT32 i = 0; i < count; i++)
{
SafeRelease(&ppDevices[i]);
}
CoTaskMemFree(ppDevices);
}
}
};
HRESULT VideoSourceList::InitVideoDevices()
{
m_videoDevices.clear();
HRESULT hr = S_OK;
ChooseDeviceParam param;
CComPtr<IMFAttributes> pAttributes;
// Initialize an attribute store to specify enumeration parameters.
hr = MFCreateAttributes(&pAttributes, 1);
if (!SUCCEEDED(hr))
{
return hr;
}
// Ask for source type = video capture devices.
hr = pAttributes->SetGUID(
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
);
if (!SUCCEEDED(hr))
{
return hr;
}
// Enumerate devices.
hr = MFEnumDeviceSources(pAttributes, ¶m.ppDevices, ¶m.count);
if (!SUCCEEDED(hr))
{
return hr;
}
for (UINT32 n = 0; n < param.count; ++n)
{
WCHAR name[1024];
hr=param.ppDevices[n]->GetString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, name, 1024, NULL);
if (!SUCCEEDED(hr))
{
return hr;
}
VideoDeviceData data;
data.name = name;
m_videoDevices.push_back(data);
}
return S_OK;
}
这是 VideoSourceList.h
#pragma once
#include "atlbase.h"
#include <memory>
#include <vector>
class VideoSourceList
{
public:
VideoSourceList();
virtual ~VideoSourceList();
HRESULT GetVideoSourceCount(int& count);
HRESULT GetVideoSourceName(int index, CComBSTR& name);
private:
struct VideoDeviceData
{
CComBSTR name;
CComPtr<IMoniker> moniker;
};
std::vector<VideoDeviceData> m_videoDevices;
HRESULT InitVideoDevices();
};
这是不工作部分的属性
谢谢你的帮助。