title: Read From Media Buffer - Pointer Arithmetic C++ Syntax
body: <p>This may well have come up before but the following code is taken from an MSDN example I am modifying. I want to know how I can iterate through the contents of the buffer which contains data about a bitmap and print out the colors. Each pixel is 4 bytes of data so I am assuming the R G B values account for 3 of these bytes, and possibly A is the 4th. </p>
  
  <p>What is the correct C++ syntax for the pointer arithmetic required (ideally inside a loop) that will store the value pointed to during that iteration in to a local variable that I can use, eg. print to the console.</p>
  
  <p>Many thanks</p>
  
  <p>PS. Is this safe? Or is there a safer way to read the contents of an IMFMediaBuffer? I could not find an alternative.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>hr = pSample-&gt;ConvertToContiguousBuffer(&amp;pBuffer); // this is the BitmapData
      // Converts a sample with multiple buffers into a sample with a single IMFMediaBuffer which we Lock in memory next...
  
      // IMFMediaBuffer represents a block of memory that contains media data
  
      hr = pBuffer-&gt;Lock(&amp;pBitmapData, NULL, &amp;cbBitmapData);  // pBuffer is IMFMediaBuffer
      /* Lock method gives the caller access to the memory in the buffer, for reading or writing:
      pBitmapData - receives a pointer to start of buffer
      NULL - receives the maximum amount of data that can be written to the buffer. This parameter can be NULL.
      cbBitmapData - receives the length of the valid data in the buffer, in bytes. This parameter can be NULL.
      */
  </code></pre>