PDA

View Full Version : How to link win32 dll to project?



libed
22nd July 2011, 09:48
Hi
Im working on QT4 with Eclipse IDE. My project needs some win32 declarations (e.g. DWORD, PSP_DEVICE_INTERFACE_DETAIL_DATA) which are included in setupapi.h and setupapi.dll.
With .h header there is no problem, but how to link setupapi.dll to project?

I tried to set file: proj_name.pro


LIBS += -LC:\Windows\System32 -lsetupapi

but it doesen't work.

high_flyer
22nd July 2011, 10:56
If you are not working with cl.exe (the MS compiler) will have to use the specific compiler version setupapi.dll.
If you are using MinGW, you should give the path to the MinGW system lib folder (and make sure you have the lib in there)

libed
22nd July 2011, 12:10
Thank You for reply.
I'm using MinGW. I added the path "C:\MinGW\lib" as you said. There is no setupapi.dll but I can find there libsetupapi.a. Is that library similar to setupapi.dll?
Anyway, i still can't compile my project with the same errors. Should I modify my proj_name.pro file?

high_flyer
22nd July 2011, 12:33
what is the error you get?

libed
22nd July 2011, 12:59
I have some structures, used for detecting USB Devices (but its not the point):



class USBdevices {
DWORD propertyBufferSize = 0;
char *propertyBuffer = NULL;
SP_DEVINFO_DATA deviceInfoData;

HMODULE hHidLib;
HDEVINFO deviceInfoSet;
SP_INTERFACE_DEVICE_DATA deviceInterfaceData;
DWORD memberIndex = 0;
GUID classGuid;
PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData = NULL;
DWORD requiredSize = 0;
DWORD deviceInterfaceDetailDataSize = 0;

}

here are the error log:


USBdebives.h:27:33: error: ISO C++ forbids initialization of member 'propertyBufferSize'
USBdebives.h:27:33: error: making 'propertyBufferSize' static
USBdebives.h:27:33: error: ISO C++ forbids in-class initialization of non-const static member 'propertyBufferSize'
USBdebives.h:28:29: error: ISO C++ forbids initialization of member 'propertyBuffer'
USBdebives.h:28:29: error: making 'propertyBuffer' static


If I do something like that, everythings work fine. But I don't wanna heve variables declarations in constructor or in class method.



USBdevices::USBdevices() //constructor
{
QLibrary("setupapi.dll").load(); // adding necessary library
//and now declarations of all my variables and structs:

DWORD propertyBufferSize = 0;
char *propertyBuffer = NULL;
SP_DEVINFO_DATA deviceInfoData;

HMODULE hHidLib;
HDEVINFO deviceInfoSet;
SP_INTERFACE_DEVICE_DATA deviceInterfaceData;
DWORD memberIndex = 0;
GUID classGuid;
PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData = NULL;
DWORD requiredSize = 0;
DWORD deviceInterfaceDetailDataSize = 0;



}

high_flyer
22nd July 2011, 13:49
Your problem has nothing to do with libsetupapi, you have basic compilation errors.
The errors also state what the problem is - you are not allowed to initialize members at the deceleration - you should initialize them in class implementation.
You should first learn basic C++ syntax.

libed
22nd July 2011, 17:17
sorry. thats the case when you learn java before C++;

high_flyer
22nd July 2011, 17:22
There are Qt java bindings...