PDA

View Full Version : Creating Library using QTCreator (hiddevice)



AlphaWolfXV
2nd February 2010, 13:02
Hello all,
I am working with QT Creator 1.2.1 on Windows Vista 32bit and I would like to create a library file fora hiddevice class. I have the project set up as below... Basically I created these cpp/h files for using an hiddevice with QT and the files work fine when included in a project and utilized. Now I thought that I should put them into a ".a" file or a ".dll" file and just reference the library in the pro file of a project, negating the need to "#include <hiddevice.h>" in my project. When I build the Library project, it completes fine. When I load the libary in the other project to use, I get issues with "DWORD not naming a type" and others like it. Obviously the library was created incorrectly or my linking process is skewed. If anyone has some light they can shed on library creation with QTCreator or perhaps a better way to go about implementing what I am after, please advise!!
Thanks as always,
AlphaWolfXV

hiddevice.pro

#-------------------------------------------------
#
# Project created by QtCreator 2010-02-01T13:39:43
#
#-------------------------------------------------

QT -= gui

TARGET = hiddevice
TEMPLATE = lib

DEFINES += HIDDEVICE_LIBRARY

SOURCES += hiddevice.cpp

HEADERS += hiddevice.h\
hiddevice_global.h
LIBS += -L"../../mingw/lib" \
-lhid \
-L"../../mingw/lib" \
-lsetupapi
QMAKE_LFLAGS += -Xlinker -Bstatic



hiddevice_global.h

#ifndef HIDDEVICE_GLOBAL_H
#define HIDDEVICE_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(HIDDEVICE_LIBRARY)
# define HIDDEVICESHARED_EXPORT Q_DECL_EXPORT
#else
# define HIDDEVICESHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // HIDDEVICE_GLOBAL_H


hiddevice.h

#ifndef HIDDEVICE_H
#define HIDDEVICE_H

#include "hiddevice_global.h"
#include <qt_windows.h>
#include <dbt.h>
#include <stdlib.h>
extern "C" {
#include "../../mingw/include/ddk/hidsdi.h"
#include "../../mingw/include/setupapi.h"
}

#include <qDebug>
//#include <QThread>
#include <QMutex>
//if new version files for QT/MINGW need to remove any dependancy on #if _WIN32_WINNT >= 0x0500 to fix
//compile errors, should be in mingw/include/winuser.h, dbt.h, until we can figure out how to get it to build
//correctly~!

//Return Codes
#define HID_DEVICE_SUCCESS 0x00
#define HID_DEVICE_NOT_FOUND 0X01
#define HID_DEVICE_NOT_OPENED 0x02
#define HID_DEVICE_ALREADY_OPENED 0x03
#define HID_DEVICE_TRANSFER_TIMEOUT 0x04
#define HID_DEVICE_TRANSFER_FAILED 0x05
#define HID_DEVICE_CANNOT_GET_HID_INFO 0x06
#define HID_DEVICE_HANDLE_ERROR 0x07
#define HID_DEVICE_INVALID_BUFFER_SIZE 0x08
#define HID_DEVICE_SYSTEM_CODE 0x09
#define HID_DEVICE_UNKNOWN_ERROR 0xFF

//Max number of USB DEVICES allowed
#define MAX_USB_DEVICES 64

//Max Report Requests at a time
#define MAX_REPORT_REQUEST_XP 512
#define MAX_REPORT_REQUEST_2K 200

#define DEFAULT_REPORT_INPUT_BUFFERS 0
#define MAX_SERIAL_STRING_LENGTH 256

class HIDDEVICESHARED_EXPORT HIDDevice {
public:
HIDDevice();
void resetDeviceData();
DWORD getConnectedDeviceNum(WORD vid, WORD pid);
BYTE getSerialString(DWORD deviceIndex, WORD vid, WORD pid, LPSTR serialString, DWORD serialStringLength);
BYTE close();
bool isOpened();
BYTE Open(DWORD deviceIndex, WORD vid, WORD pid, WORD numInputBuffers);
bool getHidDevicePath(DWORD index, char* devicePath);
HANDLE openDeviceByVidPid(char* devicePath, WORD vid, WORD pid);

BYTE setReport_Feature(BYTE* buffer, DWORD bufferSize);
BYTE getReport_Feature(BYTE* buffer, DWORD bufferSize);
BYTE setReport_Interrupt(BYTE* buffer, DWORD bufferSize);
BYTE getReport_Interrupt(BYTE* buffer, DWORD bufferSize, WORD numReports, DWORD* bytesReturned);
// BYTE setReport_Control(BYTE* buffer, DWORD bufferSize); //not imp in qt/mingw...
// BYTE getReport_Control(BYTE* buffer, DWORD bufferSize); //not imp in qt/mingw...
WORD getInputReportBufferLength();
WORD getOutputReportBufferLength();
WORD getFeatureReportBufferLength();
WORD getMaxReportRequest();
bool flushBuffers();
void setTimeouts(UINT getReportTimeout, UINT setReportTimeout);
void getTimeouts(UINT* getReportTimeout, UINT* setReportTimeout);

virtual ~HIDDevice();
protected:
QMutex* mutex;
private:

HANDLE m_Handle;
bool m_DeviceOpened;

UINT m_GetReportTimeout;
UINT m_SetReportTimeout;

WORD m_InputReportBufferLength;
WORD m_OutputReportBufferLength;
WORD m_FeatureReportBufferLength;

WORD m_MaxReportRequest;

};
#define LOCK_MUTEX() mutex->lock();
#define UNLOCK_MUTEX() mutex->unlock();

#endif // HIDDEVICE_H



pro in linked application:

TARGET = WEM_ProgData
TEMPLATE = app
HEADERS += wemprogdata.h \
proginterface.h
SOURCES += wemprogdata.cpp \
main.cpp \
proginterface.cpp
INCLUDEPATH += e:/data/workingsvn/swSrcLib \
c:/data/swSrcLib
LIBS += -L"../../mingw/lib" \
-lhid \
-L"../../mingw/lib" \
-lsetupapi \
-L"../swSrcLib" \
-lhiddevice

If the implementation file is needed, please advise and I can upload!