72
72
extern bool qax_dispatchEqualsIDispatch;
73
73
extern void qax_deleteMetaObject(QMetaObject *mo);
76
75
QMap<QByteArray, QByteArray> namespaceForType;
77
76
QVector<QByteArray> strings;
78
77
QHash<QByteArray, int> stringIndex; // Optimization, speeds up generation
98
void writeHeader(QTextStream &out, const QByteArray &nameSpace, const QString &outFileName)
97
void writeHeader(QTextStream &out, const QString &nameSpace, const QString &outFileName)
100
99
out << "#ifndef QAX_DUMPCPP_" << outFileName.toUpper() << "_H" << endl;
101
100
out << "#define QAX_DUMPCPP_" << outFileName.toUpper() << "_H" << endl;
983
bool generateTypeLibrary(const QByteArray &typeLib, const QByteArray &outname, ObjectCategory category)
982
bool generateTypeLibrary(QString typeLibFile, QString outname,
983
const QString &nameSpace, ObjectCategory category)
985
QString typeLibFile(QString::fromLatin1(typeLib.constData()));
986
typeLibFile = typeLibFile.replace(QLatin1Char('/'), QLatin1Char('\\'));
987
QString cppFile(QString::fromLatin1(outname.constData()));
985
typeLibFile.replace(QLatin1Char('/'), QLatin1Char('\\'));
989
987
ITypeLib *typelib;
990
988
LoadTypeLibEx(reinterpret_cast<const wchar_t *>(typeLibFile.utf16()), REGKIND_NONE, &typelib);
998
typelib->GetDocumentation(-1, &nameString, 0, 0, 0);
999
libName = QString::fromWCharArray(nameString);
1000
SysFreeString(nameString);
1001
if (!nameSpace.isEmpty())
1002
libName = QString::fromLocal8Bit(nameSpace);
994
QString libName = nameSpace;
995
if (libName.isEmpty()) {
996
BSTR nameString = Q_NULLPTR;
997
if (SUCCEEDED(typelib->GetDocumentation(-1, &nameString, 0, 0, 0))) {
998
libName = QString::fromWCharArray(nameString);
999
SysFreeString(nameString);
1004
1003
QString libVersion(QLatin1String("1.0"));
1010
1009
typelib->ReleaseTLibAttr(tlibattr);
1013
if (cppFile.isEmpty())
1014
cppFile = libName.toLower();
1012
if (outname.isEmpty())
1013
outname = libName.toLower();
1016
if (cppFile.isEmpty()) {
1015
if (outname.isEmpty()) {
1017
1016
qWarning("dumpcpp: no output filename provided, and cannot deduce output filename");
1028
1027
QTextStream classImplOut(&classImplFile);
1029
QFile implFile(cppFile + QLatin1String(".cpp"));
1028
QFile implFile(outname + QLatin1String(".cpp"));
1030
1029
QTextStream implOut(&implFile);
1031
1030
if (!(category & (NoMetaObject|NoImplementation))) {
1032
1031
if (!implFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
1045
1044
implOut << "#define QAX_DUMPCPP_" << libName.toUpper() << "_NOINLINES" << endl;
1047
implOut << "#include \"" << cppFile << ".h\"" << endl;
1046
implOut << "#include \"" << outname << ".h\"" << endl;
1048
1047
implOut << endl;
1049
1048
implOut << "using namespace " << libName << ';' << endl;
1050
1049
implOut << endl;
1053
QFile declFile(cppFile + QLatin1String(".h"));
1052
QFile declFile(outname + QLatin1String(".h"));
1054
1053
QTextStream declOut(&declFile);
1055
1054
QByteArray classes;
1056
1055
QTextStream classesOut(&classes, QIODevice::WriteOnly);
1073
1072
declOut << "****************************************************************************/" << endl;
1074
1073
declOut << endl;
1076
QFileInfo cppFileInfo(cppFile);
1077
writeHeader(declOut, libName.toLatin1(), cppFileInfo.fileName());
1075
QFileInfo cppFileInfo(outname);
1076
writeHeader(declOut, libName, cppFileInfo.fileName());
1079
1078
UINT typeCount = typelib->GetTypeInfoCount();
1080
1079
if (declFile.isOpen()) {
1575
1575
if (category == TypeLibID) {
1576
1576
QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\\Software\\Classes\\TypeLib\\") +
1577
QString::fromLatin1(typeLib.constData()), QSettings::NativeFormat);
1578
typeLib = QByteArray();
1577
typeLib, QSettings::NativeFormat);
1579
1579
QStringList codes = settings.childGroups();
1580
1580
for (int c = 0; c < codes.count(); ++c) {
1581
typeLib = settings.value(QLatin1Char('/') + codes.at(c) + QLatin1String("/0/win32/.")).toByteArray();
1582
if (QFile::exists(QString::fromLatin1(typeLib))) {
1581
typeLib = settings.value(QLatin1Char('/') + codes.at(c) + QLatin1String("/0/win32/.")).toString();
1582
if (QFile::exists(typeLib))
1587
1586
if (!typeLib.isEmpty())
1588
fprintf(stdout, "\"%s\"\n", typeLib.data());
1587
fprintf(stdout, "\"%s\"\n", qPrintable(typeLib));
1601
1600
// not a file - search registry
1602
if (!QFile::exists(QString::fromLatin1(typeLib.constData()))) {
1601
if (!QFile::exists(typeLib)) {
1603
1602
bool isObject = false;
1604
1603
QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\\Software\\Classes"), QSettings::NativeFormat);
1606
1605
// regular string and not a file - must be ProgID
1607
1606
if (typeLib.at(0) != '{') {
1609
if (CLSIDFromProgID(reinterpret_cast<const wchar_t *>(QString(QLatin1String(typeLib)).utf16()), &clsid) != S_OK) {
1610
qWarning("dumpcpp: '%s' is not a type library and not a registered ProgID", typeLib.constData());
1608
if (CLSIDFromProgID(reinterpret_cast<const wchar_t *>(typeLib.utf16()), &clsid) != S_OK) {
1609
qWarning("dumpcpp: '%s' is not a type library and not a registered ProgID",
1610
qPrintable(typeLib));
1614
typeLib = uuid.toString().toLatin1();
1613
typeLib = QUuid(clsid).toString();
1615
1614
isObject = true;
1618
1617
// check if CLSID
1619
1618
if (!isObject) {
1620
QVariant test = settings.value(QLatin1String("/CLSID/") +
1621
QString::fromLatin1(typeLib.constData()) + QLatin1String("/."));
1619
QVariant test = settings.value(QLatin1String("/CLSID/") + typeLib + QLatin1String("/."));
1622
1620
isObject = test.isValid();
1625
1623
// search typelib ID for CLSID
1627
typeLib = settings.value(QLatin1String("/CLSID/") +
1628
QString::fromLatin1(typeLib.constData()) + QLatin1String("/Typelib/.")).toByteArray();
1625
typeLib = settings.value(QLatin1String("/CLSID/") + typeLib
1626
+ QLatin1String("/Typelib/.")).toString();
1630
1628
// interpret input as type library ID
1631
QString key = QLatin1String("/TypeLib/") + QLatin1String(typeLib);
1629
QString key = QLatin1String("/TypeLib/") + typeLib;
1632
1630
settings.beginGroup(key);
1633
1631
QStringList versions = settings.childGroups();
1634
1632
QStringList codes;
1641
1639
settings.endGroup();
1643
1641
for (int c = 0; c < codes.count(); ++c) {
1644
typeLib = settings.value(key + QLatin1Char('/') + codes.at(c) + QLatin1String("/win32/.")).toByteArray();
1645
if (QFile::exists(QString::fromLatin1(typeLib.constData()))) {
1642
typeLib = settings.value(key + QLatin1Char('/') + codes.at(c)
1643
+ QLatin1String("/win32/.")).toString();
1644
if (QFile::exists(typeLib))
1651
if (!QFile::exists(QString::fromLatin1(typeLib.constData()))) {
1652
qWarning("dumpcpp: type library '%s' not found", typeLib.constData());
1649
if (!QFile::exists(typeLib)) {
1650
qWarning("dumpcpp: type library '%s' not found", qPrintable(typeLib));
1656
if (!generateTypeLibrary(typeLib, outname, (ObjectCategory)category)) {
1657
qWarning("dumpcpp: error processing type library '%s'", typeLib.constData());
1654
if (!generateTypeLibrary(typeLib, outname, nameSpace, (ObjectCategory)category)) {
1655
qWarning("dumpcpp: error processing type library '%s'", qPrintable(typeLib));