Handling PnP WM_DEVICECHANGE messages from a DLL

Sorry this question isn’t exactly a device driver one, but it is related.

We are writing a WDM driver for a USB device under Windows 2K. Along with the driver we are writing a DLL for user applications to call. In the DLL, we want to provide a callback function to notify the application when a USB device has been added or removed. However to register for PnP notification we need to supply a window handle or a service handle, neither of which weI have. My questions are:

Can our DLL create a thread, which creates a window to handle the WD_DEVICECHANGE message?
Is there a better way to do this?
Is there any way to do this?
Is there a better forum to ask these questions?

Larry


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hello ,

HLC> We are writing a WDM driver for a USB device under Windows 2K. Along with the driver we are writing a DLL for user applications to call. In the DLL, we want to provide a callback function to
HLC> notify the application when a USB device has been added or removed. However to register for PnP notification we need to supply a window handle or a service handle, neither of which weI have.
HLC> My questions are:

HLC> Can our DLL create a thread, which creates a window to handle the WD_DEVICECHANGE message?

I have had the same problem (writing a generic solution for PnP
notication) and my solution was a new window. I have created my own
window for WM_DEVICECHANGE notification messages.
This works not for console based programs and services.

I don’t now why this notification is not avail with normal call back
function.

elli


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

to register for PnP notification we need to supply a window handle or a
service handle, neither
of which weI have. My questions are:

Can our DLL create a thread, which creates a window to handle the
WD_DEVICECHANGE

Creating hidden windows is simple :slight_smile: For instance, COM uses ones.
Since window is owned by the thread which must process its message loop,
creating a thread seems to be a good idea too.
Send WM_QUIT to the window during the shutdown procedure. The thread will
call WndProc, which must destroy the window and then the thread itself.

Max


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hello,

Here is some code that may be of help … It may need a small amount of
tweaking since i deleted and added some blocks of code without
compilation, so please take it with a pinch of salt. It should help form
a basis for what you need to do.

#define hidden_win “hidden”

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_CREATE :
return 0;

case WM_DESTROY :
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}

DWORD _RegisterHiddenWindowClass(HINSTANCE hInstance)
{
WNDCLASS wndclass;

wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 16;
wndclass.cbWndExtra = 16;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = hidden_win;
if (RegisterClass (&wndclass) == 0)
return FALSE;

return TRUE;
}
DWORD WINAPI _Worker(PVOID pData)
{
MSG msg;
HWND hWnd;

// Create tool window with no caption so that it does not show
up in the task mgr or in the task bar
hWnd = CreateWindowEx(WS_EX_TOOLWINDOW, hidden_win, NULL,
WS_POPUP,
0, 0, 0, 0, NULL,
NULL, GetModuleHandle(NULL), NULL);

if (hWnd == NULL)
ExitThread(0);

// Pass the hWnd back to the creator
(HWND *)*pData = hWnd;

// Go into a message loop …
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}

return 0;
}

// You could use the functions like so …

// Some other thread …
{
DWORD hThread, dwThreadId;
HWND hHiddenWindow;

_RegisterHiddenWindowClass(GetModuleHandle(NULL));

hThread = CreateThread(NULL, 0, _Worker, &hHiddenWindow, 0,
&dwThreadId);
if (hThread == NULL)
HANDLEREG(&rCode, ERR_INVALID_INIT);

// Want to close the window
if (hHiddenWindow != NULL)
SendMessage(hHiddenWindow, WM_QUIT, 0, 0);

// Continue …

}

Regards

  • asit

-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Tuesday, July 31, 2001 11:50 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Handling PnP WM_DEVICECHANGE messages from a DLL

to register for PnP notification we need to supply a window handle or a
service handle, neither
of which weI have. My questions are:

Can our DLL create a thread, which creates a window to handle the
WD_DEVICECHANGE

Creating hidden windows is simple :slight_smile: For instance, COM uses ones.
Since window is owned by the thread which must process its message loop,
creating a thread seems to be a good idea too.
Send WM_QUIT to the window during the shutdown procedure. The thread
will
call WndProc, which must destroy the window and then the thread itself.

Max


You are currently subscribed to ntdev as: xxxxx@greenborder.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com