title: Locking a GDI+ Bitmap in Native C++?
body: <p>I can find many examples on how to do this in managed c++ but none for unmanaged.</p>
  
  <p>I want to get all the pixel data as efficiently as possible, but some of the scan0 stuff I would need more info about so I can properly iterate through the pixel data and get each rgba value from it.</p>
  
  <p>right now I have this:</p>
  
  <pre><code>  Bitmap *b = new Bitmap(filename);
    if(b == NULL)
    {
     return 0;
    }
  
    UINT w,h;
    w = b-&gt;GetWidth();
    h = b-&gt;GetHeight();
    Rect *r = new Rect(0,0,w,h);
    BitmapData *lockdat;
   b-&gt;LockBits(r,ImageLockModeRead,PixelFormatDontCare,lockdat);
  
    delete(r);
    if(w == 0 &amp;&amp; h == 0)
    {
     return 0;
    }
  
    Color c;
  
    std::vector&lt;GLubyte&gt; pdata(w * h * 4,0.0);
  
    for (unsigned int i = 0; i &lt; h; i++) {
     for (unsigned int j = 0; j &lt; w; j++) {
      b-&gt;GetPixel(j,i,&amp;c);
  
      pdata[i * 4 * w + j * 4 + 0] = (GLubyte) c.GetR();
      pdata[i * 4 * w + j * 4 + 1] = (GLubyte) c.GetG();
      pdata[i * 4 * w + j * 4 + 2] = (GLubyte) c.GetB();
      pdata[i * 4 * w + j * 4 + 3] = (GLubyte) c.GetA();
     }
    }
    delete(b);
  
    return CreateTexture(pdata,w,h);
  </code></pre>
  
  <p>How do I use lockdat to do the equivalent of getpixel?
  Thanks</p>