Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. win32 service crashing in vista

win32 service crashing in vista

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasejsonquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Subrat Patnaik
    wrote on last edited by
    #1

    hi, i am having a service running in vista. it captures the information of the USB devices that are being used in the system. i am registering for device notification when starting the service using the RegisterDeviceNotification API, however the service is crashing when i am calling UnregisterDeviceNotification API Pasting the piece of code below....if needed i would also give the values out of debugging. please could i get some help or hints as to why my service is crashing when i am calling UnregisterDeviceNotification ?

    DWORD WINAPI service_ctrl(DWORD dwCtrlCode,DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
    {
    PDEV_BROADCAST_HDR head = (PDEV_BROADCAST_HDR )lpEventData;

    switch (dwCtrlCode) 
    {
    case SERVICE\_CONTROL\_DEVICEEVENT: 
    	if (dwEventType == DBT\_DEVICEQUERYREMOVE)
    	{
    		if(head->dbch\_devicetype == DBT\_DEVTYP\_HANDLE)
    		{	
    			PDEV\_BROADCAST\_HANDLE  db = (PDEV\_BROADCAST\_HANDLE) head;
    			DebugLog("Remove Query");
    
    
    			ht\_pIter = handleThread.find(db->dbch\_handle);
    			if ( ht\_pIter == handleThread.end( ) )
    				DebugLog("cannot find Thread ID using Handle Value ");
    			else
    			{
    
    				killThreadFunc(ht\_pIter->second.threadHandle,ht\_pIter->second.threadID);
    				DebugLog("after killThreadFunc");
    				if(!CloseHandle(db->dbch\_handle))
    				{
    
    					DebugLog("Problem in Closing Directory Handle.");
    				}
    
    				char error\[50\] = {0};
    				if(!UnregisterDeviceNotification(\*ht\_pIter->second.devNotify))
    				{
    					DebugLog("Problem in Unregistering Device notification.");
    					sprintf(error,"Error Code returned is %d",GetLastError());
    					DebugLog(error);					
    
    				}
    
    				handleThread.erase(db->dbch\_handle);
    
    				//SetEvent(hLogTrigger);
    				DebugLog("Thread Terminate Successful");
    			}
    
    		}
    		return NO\_ERROR;
    	}//end if DEVICEQUERYREMOVE
    	break;
    }
    

    }

    A 1 Reply Last reply
    0
    • S Subrat Patnaik

      hi, i am having a service running in vista. it captures the information of the USB devices that are being used in the system. i am registering for device notification when starting the service using the RegisterDeviceNotification API, however the service is crashing when i am calling UnregisterDeviceNotification API Pasting the piece of code below....if needed i would also give the values out of debugging. please could i get some help or hints as to why my service is crashing when i am calling UnregisterDeviceNotification ?

      DWORD WINAPI service_ctrl(DWORD dwCtrlCode,DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
      {
      PDEV_BROADCAST_HDR head = (PDEV_BROADCAST_HDR )lpEventData;

      switch (dwCtrlCode) 
      {
      case SERVICE\_CONTROL\_DEVICEEVENT: 
      	if (dwEventType == DBT\_DEVICEQUERYREMOVE)
      	{
      		if(head->dbch\_devicetype == DBT\_DEVTYP\_HANDLE)
      		{	
      			PDEV\_BROADCAST\_HANDLE  db = (PDEV\_BROADCAST\_HANDLE) head;
      			DebugLog("Remove Query");
      
      
      			ht\_pIter = handleThread.find(db->dbch\_handle);
      			if ( ht\_pIter == handleThread.end( ) )
      				DebugLog("cannot find Thread ID using Handle Value ");
      			else
      			{
      
      				killThreadFunc(ht\_pIter->second.threadHandle,ht\_pIter->second.threadID);
      				DebugLog("after killThreadFunc");
      				if(!CloseHandle(db->dbch\_handle))
      				{
      
      					DebugLog("Problem in Closing Directory Handle.");
      				}
      
      				char error\[50\] = {0};
      				if(!UnregisterDeviceNotification(\*ht\_pIter->second.devNotify))
      				{
      					DebugLog("Problem in Unregistering Device notification.");
      					sprintf(error,"Error Code returned is %d",GetLastError());
      					DebugLog(error);					
      
      				}
      
      				handleThread.erase(db->dbch\_handle);
      
      				//SetEvent(hLogTrigger);
      				DebugLog("Thread Terminate Successful");
      			}
      
      		}
      		return NO\_ERROR;
      	}//end if DEVICEQUERYREMOVE
      	break;
      }
      

      }

      A Offline
      A Offline
      Aescleal
      wrote on last edited by
      #2

      Why the dereference of the structure field? *ht_pIter->second.devNotify looks a bit suspect - generally you deal with handles not pointers to handles. Cheers, Ash

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups