Reputation: 13
I'm trying to create a service that detects USB being plugged in. In order to do so, I have to create a HDEVNOTIFY
via RegisterDeviceNotification(HANDLE, LPVOID, DWORD)
.
According to MSDN, about the the first argument:
A handle to the window or service that will receive device events for the devices specified in the NotificationFilter parameter. The same window handle can be used in multiple calls to RegisterDeviceNotification.
Services can specify either a window handle or service status handle.
So I did this (svcStatHandle
is a SERVICE_STATUS_HANDLE
):
hDeviceNotify = RegisterDeviceNotification( svcStatHandle,
&NotificationFilter,
DEVICE_NOTIFY_SERVICE_HANDLE);
But g++ gave the following error when compiling:
error: invalid conversion from 'SERVICE_STATUS_HANDLE {aka long unsigned int}' to 'HANDLE {aka void*}' [-fpermissive]
Based on that, I conclude that by the code I try to provide a long unsigned int
(a value) where a void*
(a pointer) is expected.
Several frustrating hours later, after the error first came out, I successfully get it working by adding -fpermissive
to the compiler command line flag (It turns into a warning), but I'd like to know exactly what is going wrong here. Providing a value where a pointer is expected doesn't sound right, and I'd like to keep my code clear from warnings.
Upvotes: 0
Views: 891
Reputation: 13
My winsvc.h
header file is found out to have an incorrect definition, as shown on the original MinGW project (pointed out by eryksun), so it's probably an outdated version as according to wikipedia, MinGW-w64 has been built in order to support 64bit and new APIs. Most importantly it contains the correct definition for SERVICE_STATUS_HANDLE
. Makes a lot of sense since I got my MinGW from that outdated source.
This means replacing with MinGW-w64 is the best way to go in the long run, but directly editing winsvc.h
also worked albeit the possibility of side-effect
Upvotes: 1