File: ComInteropHelper.cc

package info (click to toggle)
transmission 3.00-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 33,160 kB
  • sloc: ansic: 81,055; objc: 18,449; cpp: 16,303; sh: 4,470; javascript: 4,281; makefile: 1,081; xml: 139
file content (63 lines) | stat: -rw-r--r-- 1,486 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * 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() :
    m_client(new QAxObject(QLatin1String("Transmission.QtClient")))
{
}

ComInteropHelper::~ComInteropHelper()
{
}

bool ComInteropHelper::isConnected() const
{
    return !m_client->isNull();
}

QVariant ComInteropHelper::addMetainfo(QString const& metainfo)
{
    return m_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));
}