2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2015-12-16 20:01:03 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <objbase.h>
|
|
|
|
|
|
|
|
#include <QAxFactory>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
#include "ComInteropHelper.h"
|
|
|
|
#include "InteropObject.h"
|
|
|
|
|
2020-06-15 14:30:29 +00:00
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
|
2015-12-16 20:01:03 +00:00
|
|
|
QAXFACTORY_BEGIN("{1e405fc2-1a3a-468b-8bd6-bfbb58770390}", "{792d1aac-53cc-4dc9-bc29-e5295fdb93a9}")
|
2017-04-19 12:04:45 +00:00
|
|
|
QAXCLASS(InteropObject)
|
2020-11-15 21:53:42 +00:00
|
|
|
QAXFACTORY_END() // NOLINT
|
2015-12-16 20:01:03 +00:00
|
|
|
|
|
|
|
// These are ActiveQt internals; declaring here as I don't like their WinMain much...
|
2020-06-05 19:02:11 +00:00
|
|
|
extern HANDLE qAxInstance; // NOLINT
|
|
|
|
extern bool qAxOutProcServer; // NOLINT
|
|
|
|
extern wchar_t qAxModuleFilename[MAX_PATH]; // NOLINT
|
|
|
|
extern QString qAxInit(); // NOLINT
|
2015-12-16 20:01:03 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
ComInteropHelper::ComInteropHelper()
|
2023-11-21 15:02:03 +00:00
|
|
|
: client_{ new QAxObject{ QStringLiteral("Transmission.QtClient") } }
|
2015-12-16 20:01:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
bool ComInteropHelper::isConnected() const
|
2015-12-16 20:01:03 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return !client_->isNull();
|
2015-12-16 20:01:03 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
QVariant ComInteropHelper::addMetainfo(QString const& metainfo) const
|
2015-12-16 20:01:03 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return client_->dynamicCall("AddMetainfo(QString)", metainfo);
|
2015-12-16 20:01:03 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void ComInteropHelper::initialize()
|
2015-12-16 20:01:03 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
qAxOutProcServer = true;
|
2017-04-30 09:29:58 +00:00
|
|
|
::GetModuleFileNameW(nullptr, qAxModuleFilename, MAX_PATH);
|
|
|
|
qAxInstance = ::GetModuleHandleW(nullptr);
|
2015-12-16 20:01:03 +00:00
|
|
|
|
2017-04-30 09:29:58 +00:00
|
|
|
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
2017-04-19 12:04:45 +00:00
|
|
|
qAxInit();
|
2015-12-16 20:01:03 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void ComInteropHelper::registerObject(QObject* parent)
|
2015-12-16 20:01:03 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QAxFactory::startServer();
|
2023-11-21 15:02:03 +00:00
|
|
|
QAxFactory::registerActiveObject(new InteropObject{ parent });
|
2015-12-16 20:01:03 +00:00
|
|
|
}
|