transmission/qt/ComInteropHelper.cc

64 lines
1.5 KiB
C++
Raw Normal View History

2015-12-16 20:01:03 +00:00
/*
* 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)
2015-12-16 20:01:03 +00:00
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() :
m_client(new QAxObject(QLatin1String("Transmission.QtClient")))
2015-12-16 20:01:03 +00:00
{
}
ComInteropHelper::~ComInteropHelper()
2015-12-16 20:01:03 +00:00
{
}
bool ComInteropHelper::isConnected() const
2015-12-16 20:01:03 +00:00
{
return !m_client->isNull();
2015-12-16 20:01:03 +00:00
}
QVariant ComInteropHelper::addMetainfo(QString const& metainfo)
2015-12-16 20:01:03 +00:00
{
return m_client->dynamicCall("AddMetainfo(QString)", metainfo);
2015-12-16 20:01:03 +00:00
}
void ComInteropHelper::initialize()
2015-12-16 20:01:03 +00:00
{
qAxOutProcServer = true;
::GetModuleFileNameW(nullptr, qAxModuleFilename, MAX_PATH);
qAxInstance = ::GetModuleHandleW(nullptr);
2015-12-16 20:01:03 +00:00
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
qAxInit();
2015-12-16 20:01:03 +00:00
}
void ComInteropHelper::registerObject(QObject* parent)
2015-12-16 20:01:03 +00:00
{
QAxFactory::startServer();
QAxFactory::registerActiveObject(new InteropObject(parent));
2015-12-16 20:01:03 +00:00
}