Qt 4.8
Classes | Macros | Functions | Variables
qaxbase.cpp File Reference
#include "qaxobject.h"
#include <qfile.h>
#include <qwidget.h>
#include <quuid.h>
#include <qhash.h>
#include <qset.h>
#include <qpair.h>
#include <qmetaobject.h>
#include <qsettings.h>
#include <qmutex.h>
#include <qt_windows.h>
#include <ocidl.h>
#include <ctype.h>
#include "../shared/qaxtypes.h"

Go to the source code of this file.

Classes

class  MetaObjectGenerator
 
struct  MetaObjectGenerator::Method
 
struct  MetaObjectGenerator::Property
 
class  QAxBasePrivate
 
class  QAxEventSink
 
struct  QAxMetaObject
 
class  QtPropertyBag
 

Macros

#define QT_CHECK_STATE
 
#define VT_UNHANDLED(x)   case VT_##x: qWarning("QAxBase: Unhandled type %s", #x); str = #x; break;
 

Functions

static bool checkHRESULT (HRESULT hres, EXCEPINFO *exc, QAxBase *that, const QString &name, uint argerr)
 
void * qax_createObjectWrapper (int metaType, IUnknown *iface)
 
static void qax_noSuchFunction (int disptype, const QByteArray &name, const QByteArray &function, const QAxBase *that)
 
QMetaObjectqax_readClassInfo (ITypeLib *typeLib, ITypeInfo *classInfo, const QMetaObject *parentObject)
 
QMetaObjectqax_readEnumInfo (ITypeLib *typeLib, const QMetaObject *parentObject)
 
QMetaObjectqax_readInterfaceInfo (ITypeLib *typeLib, ITypeInfo *typeInfo, const QMetaObject *parentObject)
 

Variables

static QMutex cache_mutex
 
static QHash< QUuid, QMap< QByteArray, QList< QPair< QByteArray, int > > > > enum_cache
 
static QHash< QString, QAxMetaObject * > mo_cache
 
static int mo_cache_ref = 0
 
bool qax_dispatchEqualsIDispatch = true
 
QList< QByteArrayqax_qualified_usertypes
 
static QMetaObject qaxobject_staticMetaObject
 
static QMetaObject qaxwidget_staticMetaObject
 
static const uint qt_meta_data_QAxBase []
 
static const char qt_meta_stringdata_QAxBase []
 
static const char *const type_conversion [][2]
 

Macro Definition Documentation

◆ QT_CHECK_STATE

#define QT_CHECK_STATE

Definition at line 43 of file qaxbase.cpp.

◆ VT_UNHANDLED

#define VT_UNHANDLED (   x)    case VT_##x: qWarning("QAxBase: Unhandled type %s", #x); str = #x; break;

Definition at line 1975 of file qaxbase.cpp.

Referenced by MetaObjectGenerator::guessTypes().

Function Documentation

◆ checkHRESULT()

static bool checkHRESULT ( HRESULT  hres,
EXCEPINFO *  exc,
QAxBase that,
const QString name,
uint  argerr 
)
static

Definition at line 3396 of file qaxbase.cpp.

Referenced by QAxBase::dynamicCallHelper(), QAxBase::internalInvoke(), and QAxBase::internalProperty().

3397 {
3398  switch(hres) {
3399  case S_OK:
3400  return true;
3401  case DISP_E_BADPARAMCOUNT:
3402  qWarning("QAxBase: Error calling IDispatch member %s: Bad parameter count", name.toLatin1().data());
3403  return false;
3404  case DISP_E_BADVARTYPE:
3405  qWarning("QAxBase: Error calling IDispatch member %s: Bad variant type", name.toLatin1().data());
3406  return false;
3407  case DISP_E_EXCEPTION:
3408  {
3409  bool printWarning = true;
3410  unsigned short code = -1;
3411  QString source, desc, help;
3412  const QMetaObject *mo = that->metaObject();
3413  int exceptionSignal = mo->indexOfSignal("exception(int,QString,QString,QString)");
3414  if (exceptionSignal >= 0) {
3415  if (exc->pfnDeferredFillIn)
3416  exc->pfnDeferredFillIn(exc);
3417 
3418  code = exc->wCode ? exc->wCode : exc->scode;
3419  source = QString::fromWCharArray(exc->bstrSource);
3420  desc = QString::fromWCharArray(exc->bstrDescription);
3421  help = QString::fromWCharArray(exc->bstrHelpFile);
3422  uint helpContext = exc->dwHelpContext;
3423 
3424  if (helpContext && !help.isEmpty())
3425  help += QString::fromLatin1(" [%1]").arg(helpContext);
3426 
3427  if (QAxEventSink::signalHasReceivers(that->qObject(), "exception(int,QString,QString,QString)")) {
3428  void *argv[] = {0, &code, &source, &desc, &help};
3429  that->qt_metacall(QMetaObject::InvokeMetaMethod, exceptionSignal, argv);
3430  printWarning = false;
3431  }
3432  }
3433  if (printWarning) {
3434  qWarning("QAxBase: Error calling IDispatch member %s: Exception thrown by server", name.toLatin1().data());
3435  qWarning(" Code : %d", code);
3436  qWarning(" Source : %s", source.toLatin1().data());
3437  qWarning(" Description: %s", desc.toLatin1().data());
3438  qWarning(" Help : %s", help.toLatin1().data());
3439  qWarning(" Connect to the exception(int,QString,QString,QString) signal to catch this exception");
3440  }
3441  }
3442  return false;
3443  case DISP_E_MEMBERNOTFOUND:
3444  qWarning("QAxBase: Error calling IDispatch member %s: Member not found", name.toLatin1().data());
3445  return false;
3446  case DISP_E_NONAMEDARGS:
3447  qWarning("QAxBase: Error calling IDispatch member %s: No named arguments", name.toLatin1().data());
3448  return false;
3449  case DISP_E_OVERFLOW:
3450  qWarning("QAxBase: Error calling IDispatch member %s: Overflow", name.toLatin1().data());
3451  return false;
3452  case DISP_E_PARAMNOTFOUND:
3453  qWarning("QAxBase: Error calling IDispatch member %s: Parameter %d not found", name.toLatin1().data(), argerr);
3454  return false;
3455  case DISP_E_TYPEMISMATCH:
3456  qWarning("QAxBase: Error calling IDispatch member %s: Type mismatch in parameter %d", name.toLatin1().data(), argerr);
3457  return false;
3458  case DISP_E_UNKNOWNINTERFACE:
3459  qWarning("QAxBase: Error calling IDispatch member %s: Unknown interface", name.toLatin1().data());
3460  return false;
3461  case DISP_E_UNKNOWNLCID:
3462  qWarning("QAxBase: Error calling IDispatch member %s: Unknown locale ID", name.toLatin1().data());
3463  return false;
3464  case DISP_E_PARAMNOTOPTIONAL:
3465  qWarning("QAxBase: Error calling IDispatch member %s: Non-optional parameter missing", name.toLatin1().data());
3466  return false;
3467  default:
3468  qWarning("QAxBase: Error calling IDispatch member %s: Unknown error", name.toLatin1().data());
3469  return false;
3470  }
3471 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
virtual const QMetaObject * metaObject() const
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo i...
Definition: qaxbase.cpp:3245
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
virtual QObject * qObject() const =0
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
virtual int qt_metacall(QMetaObject::Call, int, void **)
Definition: qaxbase.cpp:3705
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
int indexOfSignal(const char *signal) const
Finds signal and returns its index; otherwise returns -1.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static bool signalHasReceivers(QObject *qobject, const char *signalName)
Definition: qaxbase.cpp:526

◆ qax_createObjectWrapper()

void* qax_createObjectWrapper ( int  metaType,
IUnknown *  iface 
)

Definition at line 4448 of file qaxbase.cpp.

Referenced by VARIANTToQVariant().

4449 {
4450  if (!iface)
4451  return 0;
4452 
4453  QAxObject *object = (QAxObject*)QMetaType::construct(metaType, 0);
4454  QAxBasePrivate *d = object->d;
4455 
4456  d->ptr = iface;
4457  d->initialized = true;
4458 
4459  // no release, since no addref
4460 
4461  return object;
4462 }
double d
Definition: qnumeric_p.h:62
IUnknown * ptr
Definition: qaxbase.cpp:600
The QAxObject class provides a QObject that wraps a COM object.
Definition: qaxobject.h:54
static void * construct(int type, const void *copy=0)
Returns a copy of copy, assuming it is of type type.
Definition: qmetatype.cpp:1042
uint initialized
Definition: qaxbase.cpp:597

◆ qax_noSuchFunction()

static void qax_noSuchFunction ( int  disptype,
const QByteArray name,
const QByteArray function,
const QAxBase that 
)
static

Definition at line 3748 of file qaxbase.cpp.

Referenced by QAxBase::dynamicCallHelper().

3749 {
3750  const QMetaObject *metaObject = that->metaObject();
3751  const char *coclass = metaObject->classInfo(metaObject->indexOfClassInfo("CoClass")).value();
3752 
3753  if (disptype == DISPATCH_METHOD) {
3754  qWarning("QAxBase::dynamicCallHelper: %s: No such method in %s [%s]", name.data(), that->control().toLatin1().data(), coclass ? coclass: "unknown");
3755  qWarning("\tCandidates are:");
3756  for (int i = 0; i < metaObject->methodCount(); ++i) {
3757  const QMetaMethod slot(metaObject->method(i));
3758  if (slot.methodType() != QMetaMethod::Slot)
3759  continue;
3760  QByteArray signature = slot.signature();
3761  if (signature.toLower().startsWith(function.toLower()))
3762  qWarning("\t\t%s", signature.data());
3763  }
3764  } else {
3765  qWarning("QAxBase::dynamicCallHelper: %s: No such property in %s [%s]", name.data(), that->control().toLatin1().data(), coclass ? coclass: "unknown");
3766  if (!function.isEmpty()) {
3767  qWarning("\tCandidates are:");
3768  char f0 = function.toLower().at(0);
3769  for (int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) {
3770  QByteArray signature(metaObject->property(i).name());
3771  if (!signature.isEmpty() && signature.toLower().at(0) == f0)
3772  qWarning("\t\t%s", signature.data());
3773  }
3774  }
3775  }
3776 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
virtual const QMetaObject * metaObject() const
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo i...
Definition: qaxbase.cpp:3245
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QString control() const
the name of the COM object wrapped by this QAxBase object.
Definition: qaxbase.cpp:1029
QMetaClassInfo classInfo(int index) const
Returns the meta-data for the item of class information with the given index.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray toLower() const
Returns a lowercase copy of the byte array.
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
static bool isEmpty(const char *str)
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * name() const
Returns this property&#39;s name.
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
int propertyOffset() const
Returns the property offset for this class; i.e.
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
int indexOfClassInfo(const char *name) const
Finds class information item name and returns its index; otherwise returns -1.
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.

◆ qax_readClassInfo()

QMetaObject* qax_readClassInfo ( ITypeLib *  typeLib,
ITypeInfo *  classInfo,
const QMetaObject parentObject 
)

Definition at line 1772 of file qaxbase.cpp.

1773 {
1774  MetaObjectGenerator generator(typeLib, 0);
1775  generator.addSignal("exception(int,QString,QString,QString)", "code,source,disc,help");
1776  generator.addSignal("propertyChanged(QString)", "name");
1777 
1779  BSTR bstr;
1780  if (S_OK != classInfo->GetDocumentation(-1, &bstr, 0, 0, 0))
1781  return 0;
1782 
1783  className = QString::fromWCharArray(bstr);
1784  SysFreeString(bstr);
1785 
1786  generator.readEnumInfo();
1787 
1788  TYPEATTR *typeattr;
1789  classInfo->GetTypeAttr(&typeattr);
1790  if (typeattr) {
1791  int nInterfaces = typeattr->cImplTypes;
1792  classInfo->ReleaseTypeAttr(typeattr);
1793 
1794  for (int index = 0; index < nInterfaces; ++index) {
1795  HREFTYPE refType;
1796  if (S_OK != classInfo->GetRefTypeOfImplType(index, &refType))
1797  continue;
1798 
1799  int flags = 0;
1800  classInfo->GetImplTypeFlags(index, &flags);
1801  if (flags & IMPLTYPEFLAG_FRESTRICTED)
1802  continue;
1803 
1804  ITypeInfo *interfaceInfo = 0;
1805  classInfo->GetRefTypeInfo(refType, &interfaceInfo);
1806  if (!interfaceInfo)
1807  continue;
1808 
1809  interfaceInfo->GetDocumentation(-1, &bstr, 0, 0, 0);
1810  QString interfaceName = QString::fromWCharArray(bstr);
1811  SysFreeString(bstr);
1812  QByteArray key;
1813 
1814  TYPEATTR *typeattr = 0;
1815  interfaceInfo->GetTypeAttr(&typeattr);
1816 
1817  if (flags & IMPLTYPEFLAG_FSOURCE) {
1818  if (typeattr && !(typeattr->wTypeFlags & TYPEFLAG_FHIDDEN))
1819  key = "Event Interface " + QByteArray::number(index);
1820  generator.readEventInterface(interfaceInfo, 0);
1821  } else {
1822  if (typeattr && !(typeattr->wTypeFlags & TYPEFLAG_FHIDDEN))
1823  key = "Interface " + QByteArray::number(index);
1824  generator.readFuncsInfo(interfaceInfo, 0);
1825  generator.readVarsInfo(interfaceInfo, 0);
1826  }
1827  if (!key.isEmpty())
1828  generator.addClassInfo(key.data(), interfaceName.toLatin1());
1829 
1830  if (typeattr)
1831  interfaceInfo->ReleaseTypeAttr(typeattr);
1832  interfaceInfo->Release();
1833  }
1834  }
1835 
1836  return generator.metaObject(parentObject, className.toLatin1());
1837 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * className
Definition: qwizard.cpp:137
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
int key
quint16 index
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...

◆ qax_readEnumInfo()

QMetaObject* qax_readEnumInfo ( ITypeLib *  typeLib,
const QMetaObject parentObject 
)

Definition at line 1745 of file qaxbase.cpp.

1746 {
1747  MetaObjectGenerator generator(typeLib, 0);
1748 
1749  generator.readEnumInfo();
1750  return generator.metaObject(parentObject, "EnumInfo");
1751 }

◆ qax_readInterfaceInfo()

QMetaObject* qax_readInterfaceInfo ( ITypeLib *  typeLib,
ITypeInfo *  typeInfo,
const QMetaObject parentObject 
)

Definition at line 1753 of file qaxbase.cpp.

1754 {
1755  MetaObjectGenerator generator(typeLib, typeInfo);
1756 
1758  BSTR bstr;
1759  if (S_OK != typeInfo->GetDocumentation(-1, &bstr, 0, 0, 0))
1760  return 0;
1761 
1762  className = QString::fromWCharArray(bstr);
1763  SysFreeString(bstr);
1764 
1765  generator.readEnumInfo();
1766  generator.readFuncsInfo(typeInfo, 0);
1767  generator.readVarsInfo(typeInfo, 0);
1768 
1769  return generator.metaObject(parentObject, className.toLatin1());
1770 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * className
Definition: qwizard.cpp:137
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993

Variable Documentation

◆ cache_mutex

QMutex cache_mutex
static

Definition at line 186 of file qaxbase.cpp.

◆ enum_cache

QHash<QUuid, QMap<QByteArray, QList<QPair<QByteArray, int> > > > enum_cache
static

Definition at line 184 of file qaxbase.cpp.

◆ mo_cache

QHash<QString, QAxMetaObject*> mo_cache
static

Definition at line 183 of file qaxbase.cpp.

◆ mo_cache_ref

int mo_cache_ref = 0
static

Definition at line 185 of file qaxbase.cpp.

Referenced by QAxBasePrivate::QAxBasePrivate(), and QAxBasePrivate::~QAxBasePrivate().

◆ qax_dispatchEqualsIDispatch

bool qax_dispatchEqualsIDispatch = true

◆ qax_qualified_usertypes

QList<QByteArray> qax_qualified_usertypes

Definition at line 1887 of file qaxbase.cpp.

◆ qaxobject_staticMetaObject

QMetaObject qaxobject_staticMetaObject
static
Initial value:
= {
}
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
static const uint qt_meta_data_QAxBase[]
Definition: qaxbase.cpp:3199
static const char qt_meta_stringdata_QAxBase[]
Definition: qaxbase.cpp:3220

Definition at line 3226 of file qaxbase.cpp.

Referenced by QAxBase::metaObject().

◆ qaxwidget_staticMetaObject

QMetaObject qaxwidget_staticMetaObject
static
Initial value:
= {
}
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
static const uint qt_meta_data_QAxBase[]
Definition: qaxbase.cpp:3199
static const char qt_meta_stringdata_QAxBase[]
Definition: qaxbase.cpp:3220

Definition at line 3230 of file qaxbase.cpp.

Referenced by QAxBase::metaObject().

◆ qt_meta_data_QAxBase

const uint qt_meta_data_QAxBase[]
static
Initial value:
= {
1,
0,
0, 0,
3, 10,
1, 25,
0, 0,
24, 9, 8, 8, 0x05,
55, 50, 8, 8, 0x05,
102, 80, 8, 8, 0x05,
149, 141, 0x0a095103,
0
}

Definition at line 3199 of file qaxbase.cpp.

◆ qt_meta_stringdata_QAxBase

const char qt_meta_stringdata_QAxBase[]
static
Initial value:
= {
"QAxBase\0\0name,argc,argv\0signal(QString,int,void*)\0name\0"
"propertyChanged(QString)\0code,source,desc,help\0"
"exception(int,QString,QString,QString)\0QString\0control\0"
}

Definition at line 3220 of file qaxbase.cpp.

◆ type_conversion

const char* const type_conversion[][2]
static
Initial value:
=
{
{ "float", "double"},
{ "short", "int"},
{ "char", "int"},
{ "QList<int>", "QVariantList" },
{ "QList<uint>", "QVariantList" },
{ "QList<double>", "QVariantList" },
{ "QList<bool>", "QVariantList" },
{ "QList<QDateTime>", "QVariantList" },
{ "QList<qlonglong>", "QVariantList" },
{ 0, 0 }
}

Definition at line 189 of file qaxbase.cpp.

Referenced by QAxEventSink::addSignal(), MetaObjectGenerator::replacePrototype(), and MetaObjectGenerator::replaceType().