Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

Windows Embedded CE provides COM interfaces that you can use to parse SDP records as streams. ISdpStreamdefines methods that you can use to manage streamed data. Before your application retrieves records, use the ISdpStream::Validatemethod to ensure that the raw SDP stream is valid and well formed. The application can also use the ISdpStream::VerifySequenceOfmethod to ensure that the elements of the raw SDP array are valid. To retrieve the record from the stream, use the ISdpStream::RetrieveRecordsmethod. This method returns the SDP record in a ISdpRecordarray and a count of the number of records parsed. You can then use the ISdpRecordmethods to perform SDP record operations such as retrieving the attribute of the SDP service record. For information about retrieving SDP record attributes see Searching SDP Attributes Using COM Interfaces.

The following example code shows how to implement a function to parse an SDP record, in binary format, by using ISdpStreammethods, and return the records as an ISdpRecordarray.

Copy Code
STDMETHODIMP
ServiceAndAttributeSearchParse(
  UCHAR *szResponse,   // in - pointer to buffer representing 
					 // the SDP record, in binary format, 
					 // returned by the Bthnscreate tool.
  DWORD cbResponse,   // in - size of szResponse 
  ISdpRecord ***pppSdpRecords, // out - array of pSdpRecords
  ULONG *pNumRecords   // out - number of elements in pSdpRecords
array
)
{

  HRESULT hres = E_FAIL;
  *pppSdpRecords = NULL;
  *pNumRecords = 0;
  ISdpStream *pIStream = NULL;
// Create a stream object.
if
(FAILED(CoCreateInstance(__uuidof(SdpStream),NULL,CLSCTX_INPROC_SERVER,
						__uuidof(ISdpStream),(LPVOID *)
&pIStream))) 
{
  return E_FAIL;
}
// Ensure that the stream is valid and is well formed.
  hres = pIStream->Validate(szResponse,cbResponse,NULL);

  if (SUCCEEDED(hres)) 
  {
  // Ensure that the sequence of the stream is valid and is well
formed.
	hres = pIStream->VerifySequenceOf(szResponse,cbResponse,
					 SDP_TYPE_SEQUENCE,NULL,pNumRecords);
	if (SUCCEEDED(hres) && *pNumRecords > 0) 
	{
	*pppSdpRecords = (ISdpRecord **) 
	//Allocate memory for the SDP record buffer.
	CoTaskMemAlloc(sizeof(ISdpRecord*) * (*pNumRecords));
	if (pppSdpRecords != NULL) 
	{
		 // Retrieve the SDP records from the stream.
		 hres = pIStream->RetrieveRecords ( szResponse, 
					cbResponse,*pppSdpRecords,pNumRecords);
		//If retrieval of records from the stream failed,
		// free memory allocated to the SDP record array and set
the 
		// SDP record count to zero (0).
		if (!SUCCEEDED(hres)) 
		{
			CoTaskMemFree(*pppSdpRecords);
			*pppSdpRecords = NULL;
			*pNumRecords = 0;
		 }
	 }
	 else 
	 {
		hres = E_OUTOFMEMORY;
	 }
	 }
  }
  // Release the stream.
  if (pIStream != NULL) 
  {
	pIStream->Release();
	pIStream = NULL;
  }
  return hres;
}

See Also