1

I recently got one .NET project to compile without further knowledge from previous developers and after fixing most errors (I am using visual studio 2017 and project's previous version was like this)

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1

I am still getting error

Line Suppression State Error LNK2022 metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (ChooseDeviceParam): (0x02000273).

here is part of code where "ChooseDeviceParam" is declared (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;
}

and here is 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();
};

here are properties of not working part

Thank you for help.

aptnutella
  • 11
  • 2
  • It is not obvious how this type could have been defined more than once from the snippets. But clearly you should never have to troubleshoot this kind of error, this is not managed code at all and getting the type into the metadata is not useful. You need to partition the code in your project better, moving this code into a static library project that is compiled without /clr in effect is a decent way to get there. – Hans Passant Aug 04 '17 at 14:12

1 Answers1

0

Well, I think it is because 2 diffferent cpp files had structure named ChooseDeviceParam so I renamed one of them (ofc renamed all occurrences of this structure in project as well) and now I am not getting this error anymore (new errors appeared but I think they have nothing to do with this problem)

aptnutella
  • 11
  • 2