Files
transmission/qt/ComInteropHelper.cc
Charles Kerr 9d313a8816 sonarcloud warnings 9 (#1511)
* refactor: const correctness 

* refactor: fix some implicit conversions

* refactor: make local pointers const if their objects are not modified

* refactor: do not cast away const in torrent-cell-renderer

* refactor: remove call to deprecated gtk_icon_size_lookup_for_settings

* refactor: member functions that do not mutate their objects should be declared const

* chore: do not end comments with a semicolon
2020-11-08 21:31:02 -06:00

60 lines
1.5 KiB
C++

/*
* This file Copyright (C) 2015 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
*/
#include <windows.h>
#include <objbase.h>
#include <QAxFactory>
#include <QString>
#include <QVariant>
#include "ComInteropHelper.h"
#include "InteropObject.h"
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
QAXFACTORY_BEGIN("{1e405fc2-1a3a-468b-8bd6-bfbb58770390}", "{792d1aac-53cc-4dc9-bc29-e5295fdb93a9}")
QAXCLASS(InteropObject)
QAXFACTORY_END()
// These are ActiveQt internals; declaring here as I don't like their WinMain much...
extern HANDLE qAxInstance; // NOLINT
extern bool qAxOutProcServer; // NOLINT
extern wchar_t qAxModuleFilename[MAX_PATH]; // NOLINT
extern QString qAxInit(); // NOLINT
ComInteropHelper::ComInteropHelper() :
client_(new QAxObject(QStringLiteral("Transmission.QtClient")))
{
}
bool ComInteropHelper::isConnected() const
{
return !client_->isNull();
}
QVariant ComInteropHelper::addMetainfo(QString const& metainfo) const
{
return client_->dynamicCall("AddMetainfo(QString)", metainfo);
}
void ComInteropHelper::initialize()
{
qAxOutProcServer = true;
::GetModuleFileNameW(nullptr, qAxModuleFilename, MAX_PATH);
qAxInstance = ::GetModuleHandleW(nullptr);
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
qAxInit();
}
void ComInteropHelper::registerObject(QObject* parent)
{
QAxFactory::startServer();
QAxFactory::registerActiveObject(new InteropObject(parent));
}