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
_DISCONNEC
T.
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,DoWait
NotifThrea
d,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_NOTIFICATI
ON ndisRequestNotification = {0};
NDISUIO_DEVICE_NOTIFICATIO
N 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_ADD
LINE,-1,(L
PARAM)szOu
t);
return -1;
}
do{
msgQueueOptions.dwSize = sizeof(MSGQUEUEOPTIONS);
msgQueueOptions.dwFlags = 0;
msgQueueOptions.dwMaxMessa
ges = 25;
msgQueueOptions.cbMaxMessa
ge= sizeof(NDISUIO_DEVICE_NOTI
FICATION);
msgQueueOptions.bReadAcces
s = TRUE;
hMsgQueue = CreateMsgQueue(
NULL,
&msgQueueOptions);
if (hMsgQueue == NULL)
{
wcscpy(szOut,TEXT("Could not create message queue for Ndis notifications"));
SendMessage(hWnd,MYMSG_ADD
LINE,-1,(L
PARAM)szOu
t);
break;
}
ndisRequestNotification.hM
sgQueue = hMsgQueue;
ndisRequestNotification.dw
Notificati
onTypes = NDISUIO_NOTIFICATION_MEDIA
_CONNECT |
NDISUIO_NOTIFICATION_MEDIA
_DISCONNEC
T;
if (!DeviceIoControl(g_hNdisU
io,
IOCTL_NDISUIO_REQUEST_NOTI
FICATION,
&ndisRequestNotification,
sizeof(NDISUIO_REQUEST_NOT
IFICATION)
,
NULL,
0,
NULL,
NULL))
{
wcscpy(szOut,TEXT("Error invoking Ndis Ioctl method"));
SendMessage(hWnd,MYMSG_ADD
LINE,-1,(L
PARAM)szOu
t);
break;
}
//
// NDISUIO takes it well, now party on it..
//
while(1)
{
while (WaitForSingleObject(hMsgQ
ueue,INFIN
ITE) == WAIT_OBJECT_0)
{
while (ReadMsgQueue(
hMsgQueue,
&sDeviceNotification,
sizeof(NDISUIO_DEVICE_NOTI
FICATION),
&dwBytesReturned,
1,
&dwFlags))
{
memset(szOut,0,MAX_BUFFER_
LENGTH);
switch(sDeviceNotification
.dwNotific
ationType)
{
case NDISUIO_NOTIFICATION_MEDIA
_CONNECT:
wcscpy(szOut,TEXT("Media connected"));
break;
case NDISUIO_NOTIFICATION_MEDIA
_DISCONNEC
T:
wcscpy(szOut,TEXT("Msg Close ,Media disconnected"));
break;
}
SendMessage(hWnd,MYMSG_ADD
LINE,-1,(L
PARAM)szOu
t);
break;
} //while readMsg
}//while waitForSingleObject
}
}while(FALSE);
if(hMsgQueue)
CloseHandle(hMsgQueue);
} // DoWaitNotifThread
Thanks so much!
Mag