hi Expert:
I want to detect the NIC media status when connection states change.
So register the notification of NDISUIO_NOTIFICATION_MEDIA_CONNECT and
NDISUIO_NOTIFICATION_MEDIA_DISCONNECT.
When I power off access point , display message as below:
Media disconnected. --> correct
Media connect. --> ??
Media disconnected.
Media connect.
I don't know what's happen?
Why the status of media by connected that has detected ?
What's wrong about my code ?
My platform is pocket pc 2003.
//initialization
hThread = CreateThread(NULL,0,DoWaitNotifThread,hWnd,0,(DWORD *)&rc);
DWORD WINAPI DoWaitNotifThread(PVOID pArg)
{
HWND hWnd;
HANDLE hMsgQueue = NULL;
HRESULT hr = S_OK;
// Create the ndis message queue
MSGQUEUEOPTIONS msgQueueOptions = {0};
NDISUIO_REQUEST_NOTIFICATION ndisRequestNotification = {0};
NDISUIO_DEVICE_NOTIFICATION sDeviceNotification;
DWORD dwBytesReturned;
DWORD dwFlags;
TCHAR szOut[MAX_BUFFER_LENGTH];
hWnd = (HWND)pArg;
hr = HandleCurrentDevices();
if(FAILED(hr))
{
wcscpy(szOut,TEXT("Could not handle initial Ndis devices"));
SendMessage(hWnd,MYMSG_ADDLINE,-1,(LPARAM)szOut);
return -1;
}
do{
msgQueueOptions.dwSize = sizeof(MSGQUEUEOPTIONS);
msgQueueOptions.dwFlags = 0;
msgQueueOptions.dwMaxMessages = 25;
msgQueueOptions.cbMaxMessage= sizeof(NDISUIO_DEVICE_NOTIFICATION);
msgQueueOptions.bReadAccess = TRUE;
hMsgQueue = CreateMsgQueue(
NULL,
&msgQueueOptions);
if (hMsgQueue == NULL)
{
wcscpy(szOut,TEXT("Could not create message queue for Ndis notifications"));
SendMessage(hWnd,MYMSG_ADDLINE,-1,(LPARAM)szOut);
break;
}
ndisRequestNotification.hMsgQueue = hMsgQueue;
ndisRequestNotification.dwNotificationTypes = NDISUIO_NOTIFICATION_MEDIA_CONNECT |
NDISUIO_NOTIFICATION_MEDIA_DISCONNECT;
if (!DeviceIoControl(g_hNdisUio,
IOCTL_NDISUIO_REQUEST_NOTIFICATION,
&ndisRequestNotification,
sizeof(NDISUIO_REQUEST_NOTIFICATION),
NULL,
0,
NULL,
NULL))
{
wcscpy(szOut,TEXT("Error invoking Ndis Ioctl method"));
SendMessage(hWnd,MYMSG_ADDLINE,-1,(LPARAM)szOut);
break;
}
//
// NDISUIO takes it well, now party on it..
//
while(1)
{
while (WaitForSingleObject(hMsgQueue,INFINITE) == WAIT_OBJECT_0)
{
while (ReadMsgQueue(
hMsgQueue,
&sDeviceNotification,
sizeof(NDISUIO_DEVICE_NOTIFICATION),
&dwBytesReturned,
1,
&dwFlags))
{
memset(szOut,0,MAX_BUFFER_LENGTH);
switch(sDeviceNotification.dwNotificationType)
{
case NDISUIO_NOTIFICATION_MEDIA_CONNECT:
wcscpy(szOut,TEXT("Media connected"));
break;
case NDISUIO_NOTIFICATION_MEDIA_DISCONNECT:
wcscpy(szOut,TEXT("Msg Close ,Media disconnected"));
break;
}
SendMessage(hWnd,MYMSG_ADDLINE,-1,(LPARAM)szOut);
break;
} //while readMsg
}//while waitForSingleObject
}
}while(FALSE);
if(hMsgQueue)
CloseHandle(hMsgQueue);
} // DoWaitNotifThread
Thanks so much!
Mag
by: opanzaPosted on 2006-05-04 at 07:13:30ID: 16605759
Hi,
eue,INFINI TE) returns anything apart from WAIT_OBJECT_0 (hMsgQueue signaled -> data has been put into the queue), then it won't get into the ReadMsgQueue loop again.
LINE,-1,(L PARAM)szOu t);
, ERROR_PIPE_NOT_CONNECTED, ERROR_TIMEOUT) and does not reset the signal. Or maybe the WaitForSingleObject function fails and is returning WAIT_FAILED.
If WaitForSingleObject(hMsgQu
This ReadMsgQueue loop is not such a loop since it always breaks its execution after the switch statement, whatever the dwNotificationType value is:
...
SendMessage(hWnd,MYMSG_ADD
break;
} // while readMsg
...
So maybe the ReadMsgQueue function fails for some reason (ERROR_INSUFFICIENT_BUFFER
Cheers.