PDA

View Full Version : Using ActiveX controls and dumpcpp



eli
20th July 2011, 08:13
hello:
I get a activex controls (.OCX file) from manufacturer, this active controls can access a PCI card. I want to build a GUI to control this card. I use dumpcpp to create a "dospotpc.h" and "dospotpc.cpp" file:

dumpcpp {74676A0F-BB65-48A0-8044-F453692E9A8A} -o dospotpc

in file "dospotpc.h"

/************************************************** **************************
**
** Namespace DOSPOTPCLib generated by dumpcpp from type library
** C:\Program Files\DoSpotPC.OCX\DoSpotPC.ocx
**
************************************************** **************************/

#ifndef QAX_DUMPCPP_DOSPOTPCLIB_H
#define QAX_DUMPCPP_DOSPOTPCLIB_H

// Define this symbol to __declspec(dllexport) or __declspec(dllimport)
#ifndef DOSPOTPCLIB_EXPORT
#define DOSPOTPCLIB_EXPORT
#endif

#include <qaxobject.h>
#include <qaxwidget.h>
#include <qdatetime.h>
#include <qpixmap.h>

struct IDispatch;


// Referenced namespace

namespace DOSPOTPCLib {


class DOSPOTPCLIB_EXPORT _DDoSpotPC : public QAxObject
{
public:
_DDoSpotPC(IDispatch *subobject = 0, QAxObject *parent = 0)
: QAxObject((IUnknown*)subobject, parent)
{
internalRelease();
}

/*
Method AboutBox

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline void AboutBox();

/*
Method doGetDetectorsName

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doGetDetectorsName(int numDev, QString& DetSN1, QString& DetSN2);

/*
Method doGetDeviceNumber

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doGetDeviceNumber(int Hardware, int& numDev);

/*
Method doGetMeasureData

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doGetMeasureData(int numDev, QVariant& Xo, QVariant& Yo, QVariant& Po);

/*
Method doGetMeasureDataEx

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doGetMeasureDataEx(int numDev, double& Xo, double& Yo, double& Po);

/*
Method doGetQuadPower

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doGetQuadPower(int numDev, QVariant& PQ1, QVariant& PQ2);

/*
Method doSetHardware

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doSetHardware(int Hardware, int numDev);

/*
Method doSetSystemType

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline void doSetSystemType(int AppName);

/*
Method doSetWavelength

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doSetWavelength(int numDev, int Channel, int Wave);

// meta object functions
static const QMetaObject staticMetaObject;
virtual const QMetaObject *metaObject() const { return &staticMetaObject; }
virtual void *qt_metacast(const char *);
};

// skipping event interface _DDoSpotPCEvents

// Actual coclasses
class DOSPOTPCLIB_EXPORT DoSpotPC : public QAxWidget
{
public:
DoSpotPC(QWidget *parent = 0, Qt::WindowFlags f = 0)
: QAxWidget(parent, f)
{
setControl("{74676a0f-bb65-48a0-8044-f453692e9a8a}");
}

/*
Method AboutBox

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline void AboutBox();

/*
Method doGetDetectorsName

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doGetDetectorsName(int numDev, QString& DetSN1, QString& DetSN2);

/*
Method doGetDeviceNumber

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doGetDeviceNumber(int Hardware, int& numDev);

/*
Method doGetMeasureData

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doGetMeasureData(int numDev, QVariant& Xo, QVariant& Yo, QVariant& Po);

/*
Method doGetMeasureDataEx

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doGetMeasureDataEx(int numDev, double& Xo, double& Yo, double& Po);

/*
Method doGetQuadPower

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doGetQuadPower(int numDev, QVariant& PQ1, QVariant& PQ2);

/*
Method doSetHardware

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doSetHardware(int Hardware, int numDev);

/*
Method doSetSystemType

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline void doSetSystemType(int AppName);

/*
Method doSetWavelength

For more information, see help context 0 in C:\Program Files\DoSpotPC.OCX\DoSpotPC.hlp.
*/
inline int doSetWavelength(int numDev, int Channel, int Wave);

// meta object functions
static const QMetaObject staticMetaObject;
virtual const QMetaObject *metaObject() const { return &staticMetaObject; }
virtual void *qt_metacast(const char *);
};
...................................

in class "DoSpotPC", this member function prototype:

inline int doGetDeviceNumber(int Hardware, int& numDev);
is not correct, according to the manual, this member function prototype should be

short doGetDeviceNumber(short Hardware, short* numDev);

I get stuck at here, the parameter 1 type should be a pointer. if I use this function like this:

int devNum;
s->doGetDeviceNumber(1, devNum);
I will get following error:
"Error calling IDispatch member: Type mismatch in parameter 1"

please give me some help, thx.

high_flyer
20th July 2011, 11:38
How is this related to Qt?
If I understand correctly, your problems have to do with OCX interface, not with the QAxObject...

eli
22nd July 2011, 08:36
hello:
I try to use "dynamicCall" function, too, like following code:


QAxWidget *doSpot;
doSpot = new QAxWidget(this);
doSpot->setControl("{74676A0F-BB65-48A0-8044-F453692E9A8A}");

QString str1 = "doSetSystemType(int)";
QList<QVariant> vars1;
QVariant res1;
vars1 << 0;
res1 = doSpot->dynamicCall(str1.toLatin1(), vars1);
qDebug() << res1 << vars1[0];

QString str2 = "doGetDeviceNumber(int, int&)";
QList<QVariant> vars2;
QVariant res2;
vars2 << 1 << "";
res2 = doSpot->dynamicCall(str2.toLatin1(), vars2);
qDebug() << res2 << vars2[0] << vars2[1];

QString str3 = "doSetHardware(int, int)";
QList<QVariant> vars3;
QVariant res3;
vars3 << 1 << 2;
res3 = doSpot->dynamicCall(str3.toLatin1(), vars3);
qDebug() << res3 << vars3[0] << vars3[1];

QString str4 = "doSetWavelength(int, int, int)";
QList<QVariant> vars4;
QVariant res4;
vars4 << 1 << 1 << 633;
res4 = doSpot->dynamicCall(str4.toLatin1(), vars4);
qDebug() << res4 << vars4[0] << vars4[1] << vars4[2];
vars4.clear();
vars4 << 1 << 2 << 633;
res4 = doSpot->dynamicCall(str4.toLatin1(), vars4);
qDebug() << res4 << vars4[0] << vars4[1] << vars4[2];
vars4.clear();
vars4 << 2 << 1 << 633;
res4 = doSpot->dynamicCall(str4.toLatin1(), vars4);
qDebug() << res4 << vars4[0] << vars4[1] << vars4[2];
vars4.clear();
vars4 << 2 << 2 << 633;
res4 = doSpot->dynamicCall(str4.toLatin1(), vars4);
qDebug() << res4 << vars4[0] << vars4[1] << vars4[2];

it is fine. then, I want to get some values through function "doGetMeasureDataEx", I have a problem. following code and mention is this function prototype describe in manual:


short doGetMeasureDataEx(float* measuredData);

my problem is on argument "measuredData", the argument is a array of two element returned, ie, I can get 2 measured data at array "measuredData". . then I use dynamicCall as following code:


QString str5 = "doGetMeasureDataEx(double&)";
QVariant vars5 = 0.0;
QVariant res5;
res5 = doSpot->dynamicCall(str5.toLatin1(), vars5);

I only can get 1 data, how to get this two data, please give me some help, thx.

high_flyer
22nd July 2011, 09:08
My guess is that you have to use this variant for dynamicCall():
http://doc.qt.nokia.com/latest/qaxbase.html#dynamicCall-2

eli
22nd July 2011, 11:13
to high_flyer:
thank for your answer.

I just simplify this function prototype to explain my question, this actual prototype is


short doGetMeasureDataEx(short iDev, float* x, float* y, float* p);

the argument iDev is in-parameter. these arguments (x, y, p) are out-parameter and two element array, so, I should get 6 measured data totally.

and in my qt' test program, the getting data code is :


QString str5 = "doGetMeasureDataEx(int, double&, double&, double&)";
QList<QVariant> vars5;
QVariant res5;
vars5 << 1 << 0.0 << 0.0 << 0.0 ;
res5 = doSpot->dynamicCall(str5.toLatin1(), vars5);

so, vars[1], vars[2] and vars[3] is first element data of x ,y and p, respectively. I can't get second data. please help me to solve this problem, thx.

high_flyer
22nd July 2011, 12:53
Did you read my last answer?

eli
25th July 2011, 06:35
to high_flyer:
did you mean that I have to use this function "QVariant QAxBase::dynamicCall ( const char * function, QList<QVariant> & vars )"?, in my last post, I have used this function for dynamicCall() as follwing:


QString str5 = "doGetMeasureDataEx(int, double&, double&, double&)";
QList<QVariant> vars5;
QVariant res5;
vars5 << 1 << 0.0 << 0.0 << 0.0 ;
res5 = doSpot->dynamicCall(str5.toLatin1(), vars5);

I don't understand your meaning completely, please give me more explanation. thank for your answer.

high_flyer
25th July 2011, 10:21
Sorry, for some reason my brain saw 'res5' instead of 'vars5'.

So do you mean 'vars5' has only one element in the list after the call?

eli
25th July 2011, 11:35
to high_flyer:
following code is the function prototype described in manual:

"short doGetMeasureDataEx(short iDev, float* x, float* y, float* p);"

the argument 0 ("iDev") is in-parameter. Arguments 1, 2 and 3("x", "y", "p") are out-parameter, two element array and pointer, so, I should get 6 values totally. these 6 values are stored in x[0], x[1], y[0], y[1], p[0], p[1].

and in my qt' test program, after calling "dynamicCall()" in my machine, the vars5 is: vars5[0] = 1, vars5[1] = -12.143, vars5[2] = -0.973, vars5[3] = 0.812. ie, vars5[0] = iDev, vars5[1] = x[0], vars5[2] = y[0], vars5[3] = p[0]. I can't get x[1], y[1], p[1] values.

the Qvariant can be used as a pointer? thank for your answer.

high_flyer
25th July 2011, 14:44
Ah... now I see that you didn't use the correct function signature - you have pointers as params but you were using references...
You used:

QString str5 = "doGetMeasureDataEx(int, double&, double&, double&)";
Where as the function signature is:

short doGetMeasureDataEx(short iDev, float* x, float* y, float* p);
So no wonder it doesn't work.

What you can try, is cast the double pointer addresses to long, set that as your QVariable, and then cast back after the call:


double var1 = 0.0;
double var2 = 0.0;
...
QVariant pDouble1 = (long)&var1;
QVariant pDouble2 = (long)&var2;
..
QList<QVariant> varList;
varList << pDouble1 << pDouble 2.... ;
res5 = doSpot->dynamicCall(str5.toLatin1(), varList ); //use the correct signature with pointers!!
double *pVar = varList.at(0);
var1 = *pVar;


I don't know if this will work, this is just something I would try.

eli
26th July 2011, 06:53
hello:
I use dumpcpp to create a "dospotpc.h" and "dospotpc.cpp" file before: "dumpcpp {74676A0F-BB65-48A0-8044-F453692E9A8A} -o dospotpc"
In file "dospotpc.h", this function prototype is:

inline int doGetMeasureDataEx(int numDev, double& Xo, double& Yo, double& Po);
so, I use this code to call "dynamicCall()" function:

QString str5 = "doGetMeasureDataEx(int, double&, double&, double&)";
I don't know why the function argument transform from pointer type to reference type.

eli
1st August 2011, 07:07
it doesn't seem to work successfully. I try this and get some errors while compile.