Files
transmission/qt/ComInteropHelper.cc
Charles Kerr 1f28470cf4 chore: prefer QStringLiteral (#1284)
Further reading:
* https://forum.qt.io/topic/78540/qstringliteral-vs-qlatin1string/2
* https://woboq.com/blog/qstringliteral.html
* https://www.qt.io/blog/2014/06/13/qt-weekly-13-qstringliteral

tl;dr: QLatin1Literal uses less memory than QStringLiteral; however,
since most Qt APIs require a QString argument, there's extra runtime
cost of converting QLatin1Strings to QStrings. QStringLiteral uses a
little more memory but constructs its QStrings at compile time.

ok, the `prefer-qstringliteral` branch is getting out of control: the
secondary goal of fixing a .clang-tidy issue is causing more diffs
than the primary goal. So, I'm breaking it into two separate PRs.
2020-05-29 12:40:07 -05:00

62 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 <QAxObject>
#include <QString>
#include <QVariant>
#include "ComInteropHelper.h"
#include "InteropObject.h"
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;
extern bool qAxOutProcServer;
extern wchar_t qAxModuleFilename[MAX_PATH];
extern QString qAxInit();
ComInteropHelper::ComInteropHelper() :
client_(new QAxObject(QStringLiteral("Transmission.QtClient")))
{
}
ComInteropHelper::~ComInteropHelper() = default;
bool ComInteropHelper::isConnected() const
{
return !client_->isNull();
}
QVariant ComInteropHelper::addMetainfo(QString const& metainfo)
{
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));
}