Question

I try to create a COM object and get the interface from the object in Qt. So Qt works as the COM client. In my example the COM server is the CANoe COM server.

Here is my source code of the Qt pro file and my interface.cpp file where I try to establish the connection to CANoe:

pro file:

# Add more folders to ship with the application, here
folder_01.source = qml/3com_interface
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01

# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =

# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=

# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
    interface.cpp

# Installation path
# target.path =

# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()

HEADERS += \
    CANoe.h \
    interface.h

CONFIG += qaxcontainer

interface.cpp

#include "interface.h"
#include <QDebug>
#include "objbase.h"
#include "CANoe.h"

#include "windows.h"
#include "winnls.h"
#include "shobjidl.h"
#include "objidl.h"
#include "shlguid.h"

#include "strsafe.h"


Interface::Interface(QObject *parent) :
    QObject(parent)
{
}

void Interface::trigger_slot(const QString &msg)
{


    IApplication* pIApp;
    HRESULT result;

    result = CoInitialize(NULL);

    CLSID clsid;
    result = CLSIDFromProgID(L"CANoe.Application", &clsid);

    if(SUCCEEDED(result))
    {
        qDebug() << "CLSID saved";
    }

    const IID IID_IApplication = __uuidof(IApplication);

    result = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IApplication, (void**) &pIApp);

    if(SUCCEEDED(result))
    {
        qDebug() << "Connection established";
    }

}

When I try to build the program I get the following error code: undefined reference to '_GUID const&_mingw_uuidof()'

Does someone have an idea how to create the COM interface between Qt and a COM Server? I've searched for hours in the Internet but doesn't find any explanations. Only for accessing a COM Server with Visual Studio by using ATL. But I can't use ATL in Qt.

Was it helpful?

Solution

__uuid is a convenience to obtain an GUID for a COM class, but any other method will work too. Other than that, your code should work.

The error message looks like a MinGW link error (not enough info in question to be sure), suggesting that you missed a MinGW COM library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top