Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting String Descriptors in Mac OS X User-land



Thanks Ron and Tomas for replying so quickly.

  I used this code with some slight modifications to work in C.

  Regards,

  Ashley

========================================================
Ashley Butterworth
BLUEsat Project
Website:        http://www.bluesat.unsw.edu.au/
Email:          email@hidden
Mobile:         0403-979-560
BLUEsat Office: +61 (0)2 9385-4498
BLUEsat Fax:    +61 (0)2 9385-5993
========================================================

On Tuesday, January 20, 2004, at 05:25 PM, Ron Wilson wrote:

Hi Ashley,

I do this:

(given stringIndex)

IOReturn err;

UInt8 stringDescLenInBytes;

IOUSBDevRequest devRequest;
devRequest.bmRequestType	= 0x80;		// device to host
devRequest.bRequest		= 0x06;		// GET_DESCRIPTOR
devRequest.wValue			= (0x0003 << 8) | stringIndex;
devRequest.wIndex			= 0;
devRequest.wLength		= 0x0001;
devRequest.pData			= &stringDescLenInBytes;

err = (*dev)->DeviceRequest(dev, &devRequest);
if (err == kIOReturnSuccess && stringDescLenInBytes > 0)
{
	UInt8* stringDescriptor = new UInt8[stringDescLenInBytes];
	devRequest.wLength = stringDescLenInBytes;
	devRequest.pData = stringDescriptor;

	err = (*dev)->DeviceRequest(dev, &devRequest);
	if (err == kIOReturnSuccess)
	{
		UInt8* descStr8Ptr = stringDescriptor + 2;
		UniChar* descStrPtr = reinterpret_cast<UniChar*>(descStr8Ptr);
		CFIndex uniStrLen = (stringDescLenInBytes - 2) / 2;

		// Note bytes will be swapped (USB is little endian)
		SwapUniCodeBytes(descStrPtr, uniStrLen);
		
		// now create a CFString from the UTF-16 bytes
		...
	}

	delete [] stringDescriptor;
}

--Ron
_______________________________________________
usb mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/usb
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.