【问题标题】:Error LNK2022 metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (ChooseDeviceParam): (0x02000273)错误 LNK2022 元数据操作失败(8013118D):重复类型中的布局信息不一致(ChooseDeviceParam):(0x02000273)
【发布时间】:2018-01-12 09:26:09
【问题描述】:

我最近有一个 .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, &param.ppDevices, &param.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();
};

这里是 properties 的不工作部分

感谢您的帮助。

【问题讨论】:

  • 从 sn-ps 中如何多次定义这种类型并不明显。但显然,您永远不必对此类错误进行故障排除,这根本不是托管代码,并且将类型放入元数据中没有用处。您需要更好地对项目中的代码进行分区,将此代码移动到一个在没有 /clr 的情况下编译的静态库项目中是一种不错的方法。

标签: c++ .net visual-studio lnk2022


【解决方案1】:

好吧,我认为这是因为 2 个不同的 cpp 文件具有名为 ChooseDeviceParam 的结构,所以我重命名了其中一个(ofc 也重命名了项目中所有出现的此结构),现在我不再收到此错误(出现了新错误但我认为他们与这个问题无关)

【讨论】:

    猜你喜欢
    • 2023-03-16
    • 2012-08-12
    • 2011-02-21
    • 2016-07-10
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2014-01-02
    相关资源
    最近更新 更多