PDA

View Full Version : implementing windows function in qt



aj2903
2nd December 2009, 07:48
hi..
i'm trying to convert vc++ code into QT.
in Vc++the code calls inbuilt function GetProcAddress ()

After searching on google, i found some info about it.




GetProcAddress ()
Retrieves the address of an exported function or variable from the specified dynamic-link library (DLL).
Syntax
C++

FARPROC WINAPI GetProcAddress(
__in HMODULE hModule,
__in LPCSTR lpProcName
);




I'm not sure about it i.e (GetProcAddress is windows function)
Correct if i'm wrong.

How can the same function be implemented in Qt ?

squidge
2nd December 2009, 08:08
If there's GetProcAddress, there will no doubt be LoadLibrary too somewhere, in which case, take a look at http://doc.trolltech.com/4.5/qlibrary.html

In particular, GetProcAddress should match to the 'resolve' function quite nicely.

arashadsaifi
2nd December 2009, 08:15
There is no need to implement your own function for GetProcAddress

Qt also provide the dll loading functinality through QLibrary class

you can look into this class..


here is a sample code for the same.......


QLibrary library( "dll_Name" );
library.resolve("Function_Name"); // same as GetProcAddress


I hope it will resolve your problem

sosanjay
2nd December 2009, 11:18
Is there any example of Qt In which dll is used.
When I load a dll by using GetProcAddress() I had get error i.e. function is not declare.

Can anyone have any Idea to solve this problem or small example of How to use dll in Qt.

squidge
2nd December 2009, 14:55
If GetProcAddress doesn't work for you, then Qt resolv function is unlikely to work either.

But here goes:



typedef void (*proto)();
QLibrary lib("somelib");
proto func = (proto) lib.resolve("dosomething");


you can then use 'func' as a normal function pointer, ie: func()

Note that you do not need the '.DLL' part of the library. This is assumed automatically and makes the code more portable (ie, when compiled under Linux, it will automatically add '.so' instead)