How to check USB is enable or not in c++ programing.
Plz give me some hints or sample code or links

Try Googleing it out. Or try on WIKIing it out then you will get a good idea abt it.

some times ago I wrote following code to find if present precise device.
In my case that was USB device of CDC class (or simply virtual com port).
But the principle of enumerating devices the same in every case.

// detects device presence on predefined hardware-node
// Params:
// LPSTR pszPortName[OUT]  device name which can be used to open communication device (valid only if device detected)))
// Return value:
// TRUE- device detected; FALSE-otherwise
BOOL CUsb::DetectDevice(LPSTR pszPortName/*out*/)

  DWORD   dwPropertyType;
  char    szPropertyBuffer[100];

  GUID	DeviceGuid;//guid of device class
  SP_DEVINFO_DATA devInfoData;
  // its part of a whole hardware node that looks like  
  //   "USB\\VID_04D8&PID_0005\\5&35BC3A4B&0&2"
  //vendor-id,product-id of our device to search(descriptors inbedded in hardware)
  char szDeviceID[50]="USB\\VID_04D8&PID_0002";
  char szBufferTemp[50];
  char szBufferID[100];//real vendor-id,product-id of our device
  LPOLESTR lpOleStr;//           OLECHAR we don't need with using T2OLE/OLE2T
  char* pStrTemp;

  int i;
  BOOL  bResult;

  if(NULL == pszPortName) return FALSE;//bad param
  *pszPortName = 0;

  //predefined installer-clsid (as defined in INI for our driver) (for ought i know its common 
  //for all communication devices)
  //get handler of all device-classes presented on system
  HDEVINFO  hDevInfo = ::SetupDiGetClassDevs(NULL,/* Enumerator*/0,0,
                            DIGCF_PRESENT | DIGCF_ALLCLASSES );//to get only PCI enumerator 
                                                                                // should be REGSTR_KEY_PCIENUM
  BOOL bFound=FALSE;

  devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
  //enum all devices in a set (our case is on whole system)
  for (i=0; ::SetupDiEnumDeviceInfo(hDevInfo,i,&devInfoData); i++)
     bResult= ::IsEqualCLSID(DeviceGuid,devInfoData.ClassGuid);
     if(!bResult) continue;//this device on system has not our installer-clsid (try next)

     //its device on system with our installer-clsid
     //get its hardware-node
     bResult= ::SetupDiGetDeviceInstanceId(hDevInfo,&devInfoData,szBufferID,100,NULL);
     if(!bResult) continue;//failed to get string of device-instance hardware-node

     //check if device has our vendor-id,product-id 
     if(strlen(szDeviceID)>=strlen(szBufferID)) continue;//handware-node str must be bigger 
                                                                    // 'cause it contains additionaly id of hub/root
     if(0 != strcmp(szBufferTemp,szDeviceID)) continue;//not our vendor-id,product-id 

     //extract name of com port
                                   &dwPropertyType/*out*/,(BYTE*) &szPropertyBuffer[0]/*out*/,
     if(NULL==pStrTemp) continue;
     if(NULL==pStrTemp) continue;
  ::SetupDiDestroyDeviceInfoList(hDevInfo);//free resources
  if(bFound) return TRUE;
  return FALSE;