Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting error C2664 when trying to use WinRT C++/CX in a Qt 5.6 app on Platform::String
QtWS25 Last Chance

Getting error C2664 when trying to use WinRT C++/CX in a Qt 5.6 app on Platform::String

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++c++cxwifi directwinrtqtcreator 3.6.1
5 Posts 2 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SimurrS Offline
    SimurrS Offline
    Simurr
    wrote on last edited by
    #1

    It was kind of a pain getting the C++/CX stuff working in QtCreator, but I finally got it to compile up to this point. I get this same error in Visual Studio 2015.

    The original project had other stuff in it and was from Visual Studio 2013 and Qt 5.5. I moved the project to VS 2015 and got the same error. I then recreated just the problem part from scratch to figure out any possible configuration issues. This is what I currently have running in QtCreator 3.6.1 using Qt 5.6.0.

    I'm used to C# and am new to Visual Studio and Qt so I'm guessing this is something obvious I'm missing but I can't find anything useful (to me) about this error.

    The specific error is --

    error: C2664: 'long __winRT::__getActivationFactoryByPCWSTR(void *,Platform::Guid &,void **)': cannot convert argument 1 from 'const wchar_t [44]' to 'void *'
    

    The same error happens on the lines

    String^ deviceSelector = WiFiDirectDevice::GetDeviceSelector();
    

    and

    create_task(DeviceInformation::FindAllAsync(deviceSelector)).then([this](task<DeviceInformationCollection ^> resultTask)
    

    I created a new Qt widget project with a QMainWindow. The main.cpp was not changed. Here is my MainWindow code.

    MainWindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include "appsettings.h"
    #include "ppltasks.h"
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
        QString QStringFromString(std::wstring in);
        void getDevices();
    
    };
    
    #endif // MAINWINDOW_H
    

    MainWindow.cpp

    #include "mainwindow.h"
    #include <QtWidgets>
    #include <roapi.h>
    #include <vccorlib.h>
    
    using namespace Platform;
    using namespace Windows::Devices::Enumeration;
    using namespace Windows::Devices::WiFiDirect;
    using namespace concurrency;
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        RoInitialize(RO_INIT_MULTITHREADED); // WRT stuff initialization
        getDevices();
    }
    
    MainWindow::~MainWindow()
    {
        RoUninitialize();
    }
    
    void MainWindow::getDevices()
    {
        qDebug() << "getDevices";
    
        // Find all discoverable peers with compatible roles
    
        // Get the device selector for querying WiFiDirect devices
    
        String^ deviceSelector = WiFiDirectDevice::GetDeviceSelector();
    
        create_task(DeviceInformation::FindAllAsync(deviceSelector)).then([this](task<DeviceInformationCollection ^> resultTask)
        {
            try
            {
                DeviceInformationCollection^ devInfoCollection = resultTask.get();
                if (devInfoCollection && devInfoCollection->Size > 0)
                {
                    for (unsigned int i = 0; i < devInfoCollection->Size; i++)
                    {
                        String^ Name = devInfoCollection->GetAt(i)->Name;
                        std::wstring ws(Name->Begin());
                        qDebug() << "Device:: " << QStringFromString(ws);
                    }
                }
                else
                {
                    qDebug() << "No devices...";
                }
            }
            catch (Exception^ e)
            {
                String^ eMsg = e->Message;
                std::wstring ews(eMsg->Begin());
                qDebug() << "ERROR:: " << QStringFromString(ews);
            }
        });
    }
    
    QString MainWindow::QStringFromString(std::wstring in)
    {
        std::string str(in.begin(), in.end());
        return QString(str.c_str());
    }
    
    1 Reply Last reply
    0
    • kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @Simurr
      Hello,
      The compiler error is pretty self explanatory:
      The first parameter is expected to be void * (or any other mutable pointer because of implicit conversion), but you're passing along const wchar_t [44] (which is equivalent to const wchar_t * const, which is const). So the compiler can't convert from one type to the other. Find the exact line the function is called and fix the types.

      Also, this couldn't possibly be standard C++, what's with the circumflex (^)?
      ^ is the bitwise XOR and I don't see how, or rather why, it got in so many places ...

      Kind regards.

      Read and abide by the Qt Code of Conduct

      SimurrS 1 Reply Last reply
      0
      • kshegunovK kshegunov

        @Simurr
        Hello,
        The compiler error is pretty self explanatory:
        The first parameter is expected to be void * (or any other mutable pointer because of implicit conversion), but you're passing along const wchar_t [44] (which is equivalent to const wchar_t * const, which is const). So the compiler can't convert from one type to the other. Find the exact line the function is called and fix the types.

        Also, this couldn't possibly be standard C++, what's with the circumflex (^)?
        ^ is the bitwise XOR and I don't see how, or rather why, it got in so many places ...

        Kind regards.

        SimurrS Offline
        SimurrS Offline
        Simurr
        wrote on last edited by
        #3

        @kshegunov it is not self explanatory to me because WiFiDirectDevice::GetDeviceSelector() returns a "String^" so what conversion is there?

        The WiFi Direct API is part of WinRT. That is where "^" comes from. It's the WinRT (C++/CX?) equivalent of "*", or so I understand.

        kshegunovK 1 Reply Last reply
        0
        • SimurrS Simurr

          @kshegunov it is not self explanatory to me because WiFiDirectDevice::GetDeviceSelector() returns a "String^" so what conversion is there?

          The WiFi Direct API is part of WinRT. That is where "^" comes from. It's the WinRT (C++/CX?) equivalent of "*", or so I understand.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Simurr
          Okay, where does this call __winRT::__getActivationFactoryByPCWSTR come from? The compiler should provide you with an exact line. Has MS invented some wrapper compiler for WinRT?

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • SimurrS Offline
            SimurrS Offline
            Simurr
            wrote on last edited by
            #5

            This seems to be a problem with a Qt Desktop app trying to use the WinRT libraries using C++/CX. I am getting the same error for every WinRT API call (WiFi Direct stuff) I've tried so far.

            Can Qt 5.6 use C++/CX to use parts of the WinRT API? Either this isn't going to work or I'm missing something that I would think would be documented somewhere.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved