Пример #1
0
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
//		¥ CStrArrayStore::AllocateStorage						/*e*/
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
// creates new elements pointing to an empty CCString. The array is completely destructed by the stack frame upon it's
// deletion
void CStrArrayStore::AllocateStorage(
	CProgram		&ioState,
	UInt32			inNumElements)
{
/*	mArray.InsertItemsAt(inNumElements,LArray::index_Last,(CCString*)0);
	
	for (ArrayIndexT index=1; index<=inNumElements; index++)
	{
		CCString		*str=new CCString;
		ThrowIfMemFull_(str);
		mArray[index]=str;
	}*/
	
	
	UInt32			wasCount=mArray.GetCount();

	if (inNumElements>wasCount)				// add new ones
	{
		mArray.InsertItemsAt(inNumElements-mArray.GetCount(),LArray::index_Last,(CCString*)0);
		
		// zero the ones which existed
		CreateStrings(inNumElements-wasCount,wasCount+1);
		ClearStrings(wasCount,1);
	}
	else if (inNumElements<wasCount)		// delete old ones
	{
		DeleteStrings(wasCount-inNumElements,inNumElements+1);
		mArray.RemoveItemsAt(wasCount-inNumElements,inNumElements+1);
		ClearStrings(inNumElements,1);
	}
	else
		ClearStrings(wasCount,1);

}
HRESULT CLoopbackDevice::CreateUSBDevice() {
  // Creates the USB device and initializes the device member variables
  // and creates and initializes the device qualifier. The device qualifier
  // is required for USB2.0 devices.

  HRESULT hr = S_OK;
  ISoftUSBDeviceQualifier* piDeviceQual = NULL;
  USHORT prod_id = DEVICE_EMULATOR_PROD_ID;

  hr = ::CoCreateInstance(CLSID_SoftUSBDevice, 
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          __uuidof(ISoftUSBDevice),     
                          reinterpret_cast<void**>(&m_piSoftUSBDevice));

  IfFailHrGo(hr);

  // Create the device qualifer
  hr = ::CoCreateInstance(CLSID_SoftUSBDeviceQualifier, 
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          __uuidof(ISoftUSBDeviceQualifier),     
                          reinterpret_cast<void**>(&piDeviceQual));

  IfFailHrGo(hr);

  // Setup the device qualifier
  // binary coded decimal USB version 2.0
  IfFailHrGo(piDeviceQual->put_USB(0x0200));
  // FF=Vendor specfic device class
  IfFailHrGo(piDeviceQual->put_DeviceClass(0xff)); 
  // FF = Vendor specific device sub-class
  IfFailHrGo(piDeviceQual->put_DeviceSubClass(0xff));
  // FF = Vendor specific device protocol
  IfFailHrGo(piDeviceQual->put_DeviceProtocol(0xff)); 
  // Max packet size endpoint 0
  IfFailHrGo(piDeviceQual->put_MaxPacketSize0(64)); 
  // Number of configurations
  IfFailHrGo(piDeviceQual->put_NumConfigurations(1));

  // Setup the device 
  // binary coded decimal USB version 2.0
  IfFailHrGo(m_piSoftUSBDevice->put_USB(0x0200));
  // FF=Vendor specfic device class
  IfFailHrGo(m_piSoftUSBDevice->put_DeviceClass(0xff));
  // FF = Vendor specific device sub-class
  IfFailHrGo(m_piSoftUSBDevice->put_DeviceSubClass(0xff));
  // FF = Vendor specific device protocol
  IfFailHrGo(m_piSoftUSBDevice->put_DeviceProtocol(0xff)); 
  // Max packet size endpoint 0
  IfFailHrGo(m_piSoftUSBDevice->put_MaxPacketSize0(64)); 
  // Vendor ID - Google
  IfFailHrGo(m_piSoftUSBDevice->put_Vendor(DEVICE_VENDOR_ID));
  // product id - Device Emulator
  IfFailHrGo(m_piSoftUSBDevice->put_Product(static_cast<SHORT>(prod_id))); 
  // Binary decimal coded version 1.0
  IfFailHrGo(m_piSoftUSBDevice->put_Device(0x0100));
  // Device does not suppport remote wake up
  IfFailHrGo(m_piSoftUSBDevice->put_RemoteWakeup(VARIANT_FALSE));
  // Index of the manufacturer string
  IfFailHrGo(m_piSoftUSBDevice->put_Manufacturer(STRING_IDX_MANUFACTURER));
  // Index of the product descripton string
  IfFailHrGo(m_piSoftUSBDevice->put_ProductDesc(STRING_IDX_PRODUCT_DESC)); 
  // Index of the serial number string
  IfFailHrGo(m_piSoftUSBDevice->put_SerialNumber(STRING_IDX_SERIAL_NO));
  // Indicate that the device is self-powered
  IfFailHrGo(m_piSoftUSBDevice->put_SelfPowered(VARIANT_TRUE));
  // Indicate that the device has power
  IfFailHrGo(m_piSoftUSBDevice->put_Powered(VARIANT_TRUE));

  // Create the strings associated with the device
  IfFailHrGo(CreateStrings());

  // Add the device qualifier
  IfFailHrGo(m_piSoftUSBDevice->put_DeviceQualifier(piDeviceQual));

Exit:
  RELEASE(piDeviceQual);
  return hr;
}