PDA

View Full Version : Problem calling a routine with dynamicCall



franco.amato
7th May 2010, 21:51
Hi,
I'm trying to use a com object. I have a problem with a routine named RegUserData.
The documentation says this about the RegUserData's parameters:


CardID(string/10)
OverWrite(0: no overwrite. If ID is already registered, return with result 06.,1: overwrite.)
idxDesignation
idxDepartment
FirstName(string /15)
LastName(string /15)
idxGroup (integer/0~255)
Status(1: Activate, 0: Deactivate)
WorkMode(0:finger+pass ,1:finger,2:pass,3:finger or pass,4:Only Crad,5:Only from external Reader,6:Matching on Mifare card)
WorkTimeStart()
WorkTimeEnd()
EmployeeID
RegisterMode( Finger =1, Password = 2, Finger and Password = 3, Card=4, Max=4)
CheckExpire
ExpireDateStart
ExpireDateEnd
Password(string/10)
NF(Number of fingerprint data per user Max. 2)
TemplateSize
FingerData (byte,User Fingerprint data total size depends on the number of fingerprints registered per user)

You can says that the FingerData param is at the last position.
Instead when I try to call the routine with dynamicCall the doc generated with dumpcpp says that the FingerData param is at the second position so:



/*
Method RegUserData
*/
inline bool RegUserData(const QString& CardID, QVariantList FingerData, bool OverWrite, int idxDesignation, int
idxDepartment, const QString& FirstName, const QString& LastName, int idxGroup, bool Status, int WorkMode,
const QString& WorkTimeStart, const QString& WorkTimeEnd, const QString& EmployeeID, int RegisterMode, bool
CheckExpire, const QDateTime& ExpireDateStart, const QDateTime& ExpireDateEnd, const QString& Password, int NF,
int TemplateSize);


You can see the FingerPrint data at second position.
I would know why does dumpcpp invert the order of the parameters?

Best Regards

franco.amato
7th May 2010, 23:19
Meanwhile I called the routine with the order specified by dumpcpp and I get error with the parameter 1.
Doc says that I have to pass a QString so:

bool RegUserData(QString CardID, QVariantList FingerData, bool OverWrite = 0, int idxDesignation = 0, int idxDepartment = 0, QString FirstName = 0, QString LastName = 0, int idxGroup = 0, bool Status = 0, int WorkMode = 0, QString WorkTimeStart = 0, QString WorkTimeEnd = 0, QString EmployeeID = 0, int RegisterMode = 0, bool CheckExpire = 0, QDateTime ExpireDateStart = 0, QDateTime ExpireDateEnd = 0, QString Password = 0, int NF = 0, int TemplateSize = 0);

so I wrote this code:


//cardId
QString cardId = QString::number( user->cardId(), 10 ); // cardId is a QString for example "1234567890"

//fp data
QVariantList fingerData;
int templatesize = (int)(user->templateSize());
char* fpPtr = user->fpdata();
for(int i = 0; i < templatesize; i++)
{
QVariant v = *(fpPtr+i);
fingerData.append(v);
}

paramList.append(cardId);//CardID
paramList.append(fingerData);//FingerData

bool result = m_axobj->dynamicCall("RegUserData(QString CardID, QVariantList FingerData, \
bool OverWrite = 0, int idxDesignation = 0, \
int idxDepartment = 0, QString FirstName = 0, \
QString LastName = 0, int idxGroup = 0, \
bool Status = 0, int WorkMode = 0, \
QString WorkTimeStart = 0, QString WorkTimeEnd = 0, \
QString EmployeeID = 0, int RegisterMode = 0, \
bool CheckExpire = 0, QDateTime ExpireDateStart = 0, \
QDateTime ExpireDateEnd = 0, QString Password = 0, \
int NF = 0, int TemplateSize = 0)", paramList).toBool();

And I get the error:

QAxBase: Error calling IDispatch member Type mismatch in parameter 1.

Seems it doesn't like the QString CardID, but the documentation says that I have to pass the first param as a QString as I'm doing.
Where I'm wrong?

Best Regards,
Franco

franco.amato
7th May 2010, 23:41
I also tried to call the routine directly so:


using namespace PallyCOM;
m_terminal = new PallyCOM::oTerminal(this);
m_terminal->setControl("{1AF66B3E-B0D5-4108-80B5-13E429298140}");

and in the routine I call:


bool Device::registerNewUser(UserData* user)
{
QList<QVariant> paramList;

//cardId
QString cardId = QString::number( user->cardId(), 10 );

//fp data
QVariantList fingerData;
int templatesize = (int)(user->templateSize());
char* fpPtr = user->fpdata();
for(int i = 0; i < templatesize; i++)
{
QVariant v = *(fpPtr+i);
fingerData.append(v);
}

m_terminal->RegUserData(cardId , fingerData, false );// I call one of the overloaded routines

}

In this case the prototype is this ( created by dumpcpp )

inline bool RegUserData(const QString& CardID, QVariantList FingerData, bool OverWrite);

so I also tried to change this line:


//cardId
QString cardId = QString::number( user->cardId(), 10 );

to this:


const QString& cardId = QString::number( user->cardId(), 10 );

to match the parameters needed by the RegUserData but I always get the same error at run-time.

wysota
8th May 2010, 09:12
What is the type of paramList? Are you sure the first argument to dynamicCall() should contain all the argument names and default values?

franco.amato
8th May 2010, 16:15
What is the type of paramList? Are you sure the first argument to dynamicCall() should contain all the argument names and default values?

Wysota hi,
how can I check the type of paramList? And how can I check if the first argument to dynamicCall() should contain all the argument names and default values as you asked?
This is what the generateDocumentation produced:


bool result = m_axobj->dynamicCall("RegUserData(QString CardID, QVariantList FingerData, \
bool OverWrite = 0, int idxDesignation = 0, \
int idxDepartment = 0, QString FirstName = 0, \
QString LastName = 0, int idxGroup = 0, \
bool Status = 0, int WorkMode = 0, \
QString WorkTimeStart = 0, QString WorkTimeEnd = 0, \
QString EmployeeID = 0, int RegisterMode = 0, \
bool CheckExpire = 0, QDateTime ExpireDateStart = 0, \
QDateTime ExpireDateEnd = 0, QString Password = 0, \
int NF = 0, int TemplateSize = 0)", paramList).toBool();

Best Regards,

SixDegrees
8th May 2010, 16:21
how can I check the type of paramList? And how can I check if the first argument to dynamicCall() should contain all the argument names and default values

Kind of a wild thought, but maybe you could read the documentation?

Or, if you're using some sort of introspection, maybe you could accept what it tells you and use those arguments and order?

franco.amato
8th May 2010, 18:56
Kind of a wild thought, but maybe you could read the documentation?

Or, if you're using some sort of introspection, maybe you could accept what it tells you and use those arguments and order?

I used those arguments and order. I gave a QString as 1 argument as it asked for and it gave to me such error "Type mismatch in parameter 1"

franco.amato
8th May 2010, 19:09
What is the type of paramList? Are you sure the first argument to dynamicCall() should contain all the argument names and default values?

Wysota sorry,
I didn't understand you well yestarday. paramList is of type QVariantList.

Best,

wysota
9th May 2010, 00:20
Remember that in C++ indexing usually starts at 0 so "1" probably means the second argument.

franco.amato
9th May 2010, 19:55
Remember that in C++ indexing usually starts at 0 so "1" probably means the second argument.

Hi in that case the second argument is a QVariantList as shown here:


bool result = m_axobj->dynamicCall("RegUserData(QString CardID, \
QVariantList FingerData, \ <--second param
bool OverWrite = 0, int idxDesignation = 0, \
int idxDepartment = 0, QString FirstName = 0, \
QString LastName = 0, int idxGroup = 0, \
bool Status = 0, int WorkMode = 0, \
QString WorkTimeStart = 0, QString WorkTimeEnd = 0, \
QString EmployeeID = 0, int RegisterMode = 0, \
bool CheckExpire = 0, QDateTime ExpireDateStart = 0, \
QDateTime ExpireDateEnd = 0, QString Password = 0, \
int NF = 0, int TemplateSize = 0)", paramList).toBool();

FingerData is an array of chars so to convert it in QVariantList I used this code:


//fp data
QVariantList fingerData; // the second param
int templatesize = (int)(user->templateSize()); //template size = 352
//I get the pointer to the char array containing the finger print data
char* fpPtr = user->fpdata(); //( char array[templatesize] )
for(int i = 0; i < templatesize; i++)
{
QVariant v = *(fpPtr+i); // I convert every element of the char array to a QVariant
fingerData.append(v); // and I add it to the QVarianlList
}

I don't know another way to convert a char array to a QVariantList, but maybe this is not the correct way.

franco.amato
10th May 2010, 17:59
I changed the code to convert a char array to a QVariantList so:


//fp data
QVariantList fingerData;
char* fpPtr = user->fpdata(); //I get the ptr to the char array
QVariant v(fpPtr); I create a QVariant
fingerData.append(v); //and add it to a QVariantList

But I still get the error type mismatch in parameter 1
and more: my char array has 352 elements instead with this code the fingerData has only 225 elements.
Some elements are missing but I don't know where.

I have no idea idea of where I'm wrong.
Can anyone help me?