I took this code
as example to write a service. And I made some changes in my main function in such a way to work with command line parameters and removed
#define UNICODE
#define WINVER 0x502
Am using “MINGW”.
Am getting the following errors:
usb_detect.c: In function 'ServiceMain':
usb_detect.c:123:16: error: unknown type name 'DEV_BROADCAST_DEVICEINTERFACE'
usb_detect.c:132:41: error: request for member 'dbcc_size' in something not a structure or union
usb_detect.c:132:61: error: 'DEV_BROADCAST_DEVICEINTERFACE' undeclared (first use in this function)
usb_detect.c:132:61: note: each undeclared identifier is reported only once for each function it appears in
usb_detect.c:133:41: error: request for member 'dbcc_devicetype' in something not a structure or union
usb_detect.c:133:60: error: 'DBT_DEVTYP_DEVICEINTERFACE' undeclared (first use in this function)
usb_detect.c:136:117: error: 'DEVICE_NOTIFY_SERVICE_HANDLE' undeclared (first use in this function)
usb_detect.c:136:148: error: 'DEVICE_NOTIFY_ALL_INTERFACE_CLASSES' undeclared (first use in this function)
If I uncomment the unicode and winver there are no errors, but command line parameters are not working..
I included dbt.h too..
The
DEV_BROADCAST_DEVICEINTERFACEstructure is only supported on Windows XP and later (as well as some of the other APIs that this code relies upon). It won’t be defined in the Windows headers unless you’re targeting that version of Windows or later.To make sure that it’s defined, you need to explicitly specify your target version of Windows at the top of your header file before you include
Windows.h.The typical pattern looks something like this:
The original version of the code you tried had this line, which you removed:
That explicitly set the target Windows version to Windows Server 2003 (Windows NT v5.2). Removing it means that you revert to the lowest common denominator, which is a version of Windows prior to XP, where the
DEV_BROADCAST_DEVICEINTERFACEstructure is not defined.It’s also not clear why you’re removing the
UNICODEdefine. It’s 2012—any app you’re building should be targeting Unicode. Leave that defined as well.