PDA

View Full Version : using com dll



adam.com
11th July 2011, 20:45
in vs2010 c++ i used the following code to use some functions in a dll file that i don't have its header


#import "dll path"
HRESULT hr = CoInitialize(NULL);
if (hr==S_OK)
{cout<<"INITIALIZED\n";}

Trans_ATLLib::ITransCriptPtr Trans;
hr = Trans.CreateInstance(__uuidof(Trans_ATLLib::TransC ript));
if (hr==S_OK)
{cout<<"INSTANCE CREATED\n";}

hr =Trans->EnableLastCharTashkeel(true);
if (hr==S_OK)
{cout<<"EnableLastCharTashkeel DONE\n";}

hr =Trans->EnableEmphaticLAM_RAA(true);
if (hr==S_OK)
{cout<<"EnableEmphaticLAM_RAA DONE\n";}

VARIANT_BOOL test;
test = Trans->SetText(arabic_string);
if (test==0)
{cout<<"error in setting the arabic sting\n";}

string result;
result = Trans->GetResult();

istringstream iss(result);
vector<string> phonemes;
copy(istream_iterator<string>(iss),istream_iterator<string>(),back_inserter<vector<string> >(phonemes));
return phonemes;

}

but i found that qt doesn't use the same method

can any one help me in calling these functions in qt

thanks in advance

d_stranz
11th July 2011, 21:07
Look at QAxBase and related classes in the QAxContainer module.

There is a tutorial on using ActiveX / COM in Qt. Look for ActiveQt.

adam.com
11th July 2011, 21:10
can you explain in more details as i am very new to qt and if possible can you give me an example

d_stranz
11th July 2011, 21:14
Try examples-activeqt.

adam.com
11th July 2011, 21:42
sorry but i told you that this is the first time for me with qt
if possible can you convert the above code to qt code

d_stranz
11th July 2011, 23:35
No. I don't have time to do my job *and* yours. The purpose of this forum is to give advice and help so people can learn to do things themselves.

All of us were new to Qt once. We learned enough about Qt to be able to give help to others by reading and looking at the examples, making mistakes, and understanding what we did wrong.

If we simply gave you all the fish you wanted, you would never learn how to catch fish yourself, would you?

ChrisW67
12th July 2011, 00:09
Qt does not stop you using generic Windows code to interact with ActiveX/COM objects. If you have working code then use that.

Qt does provide some support for ActiveX objects so that they can be more easily used in Qt user interfaces and programs, or so that Qt components can be made for use outside.

adam.com
12th July 2011, 18:18
No. I don't have time to do my job *and* yours. The purpose of this forum is to give advice and help so people can learn to do things themselves.

All of us were new to Qt once. We learned enough about Qt to be able to give help to others by reading and looking at the examples, making mistakes, and understanding what we did wrong.

If we simply gave you all the fish you wanted, you would never learn how to catch fish yourself, would you?

no i just said the words in the wrong way
i mean what is the corresponding steps in qt (how to load ,create instance,......)
any way i worked around it by using the vs code as a exe file with little changes

thank you and of course you are totally right

ChrisW67
13th July 2011, 05:29
The best example of automating an ActiveX/COM control/exe is the Qutlook example in the docs. This example uses the dumpcpp tool to give you neat proxy classes to hide the more unpleasant aspects of ActiveX. You should browse the classes provided by the dumpcpp output for your COM object.

paulanon
24th September 2011, 21:26
Hello, all. I, too, am a new user looking to call a COM dll file. Wish I had read this thread before jumping around, but I managed to get it to work a little using QAxObject. But I cannot get functions with return parameters to return values to me, other than for int&. This COM works on C#, but not with Qt. Am I doing this right?


//void GetVersionNumber (int&)
QVariantList params; params.append(0);
object->dynamicCall("GetVersionNumber(int&)", params);
std::cout << "params = " << params[0].toInt() << std::endl;
//returns 64. Great!

//void GetInstSoftwareVersion (QString&)
QVariantList params;
params.append("xx");
ptr->dynamicCall("GetInstSoftwareVersion(QString &)", params);
std::cout << "GetInstSoftwareVersion:sarray[0] = " << params[0].toString().toStdString() << std::endl;
//returns "xx" and not e.g. "1.00" Why??? Driving me nuts!

Thank you in advance.

wysota
24th September 2011, 22:17
I would assume "GetInstSoftwareVersion" takes a different parameter type than QString since the latter is a Qt type that is unknown to other frameworks. I suggest you consult the manual for this "GetInstSoftwareVersion" call.

paulanon
26th September 2011, 22:09
Thank you for the response.
The manual uses "BSTR FAR*" I do not know what "FAR" is, but "BSTR" is handled by Qt (http://doc.qt.nokia.com/latest/qaxbase.html). Is there a way to know this is a problem or not?

I am thinking the parameter is handled by Qt since the generated API for this DLL library says to use QString&:

1) The documentation says:
long GetInstSoftwareVersion(BSTR FAR* pbstrInstSoftwareVersion)

2) If I use Qt dumpcpp.exe, the header generated shows:
class MSFILEREADERLIB_EXPORT IXRawfile : public QAxObject
{ ...
inline void GetInstSoftwareVersion(QString& pbstrInstSoftwareVersion);
...};


3) If I use:
QAxObject * ptr = new QAxObject ( "MSFileReader.XRawfile", 0 );
std::cout << ptr->generateDocumentation().toStdString() << std::endl;

I get:
void GetInstSoftwareVersion (QString& pbstrInstSoftwareVersion) [slot]
method GetInstSoftwareVersion
Connect a signal to this slot:
QObject::connect(sender, SIGNAL(someSignal(QString&)), object, SLOT(GetInstSoftwareVersion(QString&)));
Or call the function directly:
QVariantList params = ...
object->dynamicCall("GetInstSoftwareVersion(QString&)", params);