PDA

View Full Version : Conflicting header definitions



jacky
3rd May 2009, 18:26
I use the QT SDK 4.5.1 in WindowsXP sp3 and work in QT Creator 1.1.0.

I have to use WinDDK to retrive USB flash disk information. My application has to include three files:
#include <windows.h>
#include <winioctl.h>
#include <ddk/ntddstor.h>

While building, I get a lot of double definitions as following:

In file included from main.cpp:20:
D:/Qt/2009.02/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/ddk/ntddstor.h:299: error: redefinition of `struct _STORAGE_DEVICE_NUMBER'
D:/Qt/2009.02/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/winioctl.h:523: error: previous definition of `struct _STORAGE_DEVICE_NUMBER'
D:/Qt/2009.02/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/ddk/ntddstor.h:303: error: conflicting declaration 'typedef int STORAGE_DEVICE_NUMBER'
D:/Qt/2009.02/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/winioctl.h:527: error: 'STORAGE_DEVICE_NUMBER' has a previous declaration as `typedef struct _STORAGE_DEVICE_NUMBER STORAGE_DEVICE_NUMBER'
D:/Qt/2009.02/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/ddk/ntddstor.h:303: error: declaration of `typedef int STORAGE_DEVICE_NUMBER'

Please give me some advices to work around this issue.

Many thanks in advance.

Lykurg
3rd May 2009, 18:38
...and where is the connection to Qt?

jacky
3rd May 2009, 18:40
Thanks for your quick reply.

I am working in QT Creator 1.1.0. The code is built in QT and I think MINGW is compiler.

Could you please give me some advices?

Many thanks in advance.

Lykurg
3rd May 2009, 18:44
MinGW has nothing to do with Qt. Different things. Your problems has only to do with WinDDK what ever that is. According to your error messages: Do you need all of that header files? They are conflicting each other...

jacky
3rd May 2009, 18:46
Could you please suggest where my post should be to get some advices?
If you know how to retrieve USB stick without using WinDDK in QT please help me.

Boron
3rd May 2009, 18:49
The WinDDK is the "Windows Device Driver Kit".
Maybe deleting one of the include lines of winioctl.h or ntddstor.h might help?

jacky
3rd May 2009, 18:51
My application is based on QT. What I have to do is to retrieve the Removable Disks (USB stick) information
I think I should post my fragment of code that causes the issue here


HANDLE hDisk;
DISK_GEOMETRY diskGeometry;
DWORD dwBytes;

for (int i = 0; i < 255; i ++)
{
wchar_t str[18];
swprintf (str, L"\\\\.\\PhysicalDrive%d", i);
hDisk = CreateFile(str, MAXIMUM_ALLOWED, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL);
if (hDisk != INVALID_HANDLE_VALUE)
{
DeviceIoControl(hDisk, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &diskGeometry, sizeof (DISK_GEOMETRY), &dwBytes, NULL);
// Only proceed if disk is a removable media
if (diskGeometry.MediaType == RemovableMedia)
{
// Display disk information ....

// TODO: Display USB reader information
}
}
}


Many thanks in advacne.

jacky
3rd May 2009, 19:02
The WinDDK is the "Windows Device Driver Kit".
Maybe deleting one of the include lines of winioctl.h or ntddstor.h might help?

Thanks for your advice. This may help in case of less code.

That code fragment is a small sample one. I think it is infeasible when the code has to add more and include more files such as
#include <ddk/cfgmgr32.h>

Boron
3rd May 2009, 19:27
So it seems that we can blame MS for ugly header files, where the same struct is defined in different headers :mad:.

Perhaps you can separate the code in different modules.
One module includes (beside other headers if necessary ) winioctl.h, the other modules includes ntddstor.h.

faldzip
4th May 2009, 00:18
I just want to notice that your problem (even if your app is made with a lot of Qt classes) i connected only with Win API and DDK and whatever... but your problem is not connected qith Qt at all - so the better place for your post is in some Windows forum, or you can search for some info at http://msdn.com.

And now few words about your error: it says that there is struct _STORAGE_DEVICE_NUMBER which is defined twice: first time in one header (ntddstor.h) and second time in second header (winioctl.h). So maybe you just don't need those both headers and one should be enough?

jacky
4th May 2009, 03:49
Many thank Boron and faldżip for your suggestions.

I post this issue here in hope to find someone, who met this issue, to give me some advices to work around this. And this also helps other QT developers who will meet this issue to solve it faster in future. I doesn't post here to blame anyone who produced those ugly header files.

I am newbie in QT but I have 10+ years using Microsoft VC++ so that I am so sure that these DDK header files produced by MINGW not by Microsoft.


Perhaps you can separate the code in different modules.
One module includes (beside other headers if necessary ) winioctl.h, the other modules includes ntddstor.h.
The issue happens again when I combine two modules into one application.


And now few words about your error: it says that there is struct _STORAGE_DEVICE_NUMBER which is defined twice: first time in one header (ntddstor.h) and second time in second header (winioctl.h). So maybe you just don't need those both headers and one should be enough?
It is a long list of "defined twice" like this and I only posted here a few one as a sample so it must take a lot of time to remove them. And I am not sure that my application will work fine without crash if I manually remove them. Please tell me how you think about this case.

Many thanks again for your advices. I am still looking around to find someone who got the same issue to help me.

jacky
4th May 2009, 07:14
I see many people asking what my question has to do with QT. The problem is that I use QT for an application which has to run on Macintosh, Windows and Linux and it must be able to read a USB. Original it was a Windows VC++ application and I want to get rid of that completely hence I started to redo all in QT. Many users still use the original application and therefore we have to be able to have the QT version to run on Windows as well.

If any person here can advise how I can read the USB information (Serial number, provider, other information) I would very much appreciate it.

faldzip
4th May 2009, 08:35
I see many people asking what my question has to do with QT. The problem is that I use QT for an application which has to run on Macintosh, Windows and Linux and it must be able to read a USB. Original it was a Windows VC++ application and I want to get rid of that completely hence I started to redo all in QT. Many users still use the original application and therefore we have to be able to have the QT version to run on Windows as well.
OK, but your question at the beginning is about how to make those specific Win32 headers and functions work. And it is independent of use of Qt.

If any person here can advise how I can read the USB information (Serial number, provider, other information) I would very much appreciate it.
Try looking for libusb (http://libusb.wiki.sourceforge.net/) and/or LibUsb-Win32 (http://libusb-win32.sourceforge.net/).

jacky
4th May 2009, 10:51
I have just taken a look at libusb, it is not implemented for Windows because I see there is a <poll.h> include in the core.c file. Do you know how to work around it in Windows?

I will take a look at LibUsb-Win32 to see if it helps.

I will ask you when I get stuck.

Many thanks for your help.