Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IUnknown is an ambiguous symbol #5218

Closed
nlogozzo opened this issue Jun 18, 2021 · 4 comments
Closed

IUnknown is an ambiguous symbol #5218

nlogozzo opened this issue Jun 18, 2021 · 4 comments
Labels

Comments

@nlogozzo
Copy link

nlogozzo commented Jun 18, 2021

Hi all,
I'm trying to get my C++ WinUI 3 Win32 app to work with a FolderPicker. I included #include <shobjidl.h> to set up my FolderPicker:

IAsyncAction MainWindow::MenuOpenFolder(const IInspectable& sender, const RoutedEventArgs& e)
    {
        FolderPicker folderPicker;
        folderPicker.as<IInitializeWithWindow>()->Initialize(GetActiveWindow());
        folderPicker.FileTypeFilter().Append(L"*");
        StorageFolder result = co_await folderPicker.PickSingleFolderAsync();
        if (result)
        {
            Configuration config = Configuration::LoadConfiguration();
            std::string folderPath = to_string(result.Path());
            m_musicFolder.FolderPath(folderPath);
            config.PreviousMusicFolderPath(folderPath);
            LblStatus().Text(result.Path());
            Configuration::SaveConfiguration(config);
            MenuRefreshFolder(nullptr, nullptr);
        }
    }

However, I'm getting a IUnknown is an ambiguous symbol error as a result of including that file.
This is my pch.h file for reference as well:

#pragma once

#include <windows.h>
#include <unknwn.h>
#include <restrictederrorinfo.h>
#include <hstring.h>

// Undefine GetCurrentTime macro to prevent
// conflict with Storyboard::GetCurrentTime
#undef GetCurrentTime

#include <winrt/Microsoft.UI.Composition.h>
#include <winrt/Microsoft.UI.Xaml.h>
#include <winrt/Microsoft.UI.Xaml.Controls.h>
#include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
#include <winrt/Microsoft.UI.Xaml.Data.h>
#include <winrt/Microsoft.UI.Xaml.Interop.h>
#include <winrt/Microsoft.UI.Xaml.Markup.h>
#include <winrt/Microsoft.UI.Xaml.Media.h>
#include <winrt/Microsoft.UI.Xaml.Navigation.h>
#include <winrt/Microsoft.UI.Xaml.Shapes.h>
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Storage.Pickers.h>
#include <winrt/Windows.System.h>
#include <winrt/Windows.UI.Xaml.Interop.h>

How can I fix the ambiguity?

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Jun 18, 2021
@nlogozzo nlogozzo changed the title IUnkown is an ambiguous symbol IUnknown is an ambiguous symbol Jun 18, 2021
@RealTommyKlein
Copy link
Contributor

You'd need to disambiguate based on what kind of IUnknown you're expecting (::IUnknown for the ABI version, or ::winrt::Windows::Foundation::IUnknown for the C++/WinRT struct). The shobjidl.h header expects the ABI version, so you may be able to resolve this with something like using IUnknown = ::IUnknown;. @Scottj1s may also have a better idea of how to resolve this.

@nlogozzo
Copy link
Author

@RealTommyKlein I changed the method to something like this:

IAsyncAction MainWindow::MenuOpenFolder(const IInspectable& sender, const RoutedEventArgs& e)
    {
        FolderPicker folderPicker;
        {
            using IUnknown = ::IUnknown;
            folderPicker.as<IInitializeWithWindow>()->Initialize(GetActiveWindow());
        }
        folderPicker.FileTypeFilter().Append(L"*");
        StorageFolder result = co_await folderPicker.PickSingleFolderAsync();
        if (result)
        {
            Configuration config = Configuration::LoadConfiguration();
            std::string folderPath = to_string(result.Path());
            m_musicFolder.FolderPath(folderPath);
            config.PreviousMusicFolderPath(folderPath);
            LblStatus().Text(result.Path());
            Configuration::SaveConfiguration(config);
            MenuRefreshFolder(nullptr, nullptr);
        }
    }

And i'm still getting the issue. I also moved it to the top of the window same thing

@RealTommyKlein
Copy link
Contributor

It'd need to be in your precompiled header instead of the place you're using it, since I'm guessing the error is happening when including the shobjidl.h header. But the real issue is probably something in your code like:

using namespace winrt::Windows::Foundation;

That allows the WinRT IUnknown to be referenced without fully qualifying its namespace, causing ambiguity with the ABI IUnknown.

@StephenLPeters StephenLPeters added question product-winui3 WinUI 3 issues and removed needs-triage Issue needs to be triaged by the area owners labels Jun 18, 2021
@nlogozzo
Copy link
Author

Removing using namespace winrt::Windows::Foundation; from MainWindow.xaml.cpp solved my issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants