title: BitBlt function produces empty bitmap when compiled for x86 in .NET 2.0 VB app
body: <p>I have a BitBlt wrapper function in my VB project.  It works just fine when compiled as Any CPU, but when I aim it at x86 it creates an empty bitmap.  I must use x86 as other parts of the app require it.  Any ideas what could be wrong?  Here is the code:</p>
  
  <pre><code>Imports System.Drawing.Imaging
  
  ''' &lt;summary&gt;
  ''' Provides the static method ControlCapture used to
  ''' take screenshots of the specified control.
  ''' &lt;/summary&gt;
  ''' &lt;remarks&gt;This fails unless compiled targeting Any CPU!!!&lt;/remarks&gt;
  Public Class ControlCapture
  
      ''' &lt;summary&gt;
      ''' Pointer to gdi.exe win32 function.
      ''' &lt;/summary&gt;
      ''' &lt;param name="hDestDC"&gt;destination device context&lt;/param&gt;
      ''' &lt;param name="x"&gt;x coord. of output rectangle&lt;/param&gt;
      ''' &lt;param name="y"&gt;y coord. of output rectangle&lt;/param&gt;
      ''' &lt;param name="nWidth"&gt;width of source and dest. rectangle&lt;/param&gt;
      ''' &lt;param name="nHeight"&gt;height of source and dest. rectangle&lt;/param&gt;
      ''' &lt;param name="hSrcDC"&gt;source device context&lt;/param&gt;
      ''' &lt;param name="xSrc"&gt;x coord. of rectangle to capture&lt;/param&gt;
      ''' &lt;param name="ySrc"&gt;y coord. of rectangle to capture&lt;/param&gt;
      ''' &lt;param name="dwRop"&gt;mode (raster op)&lt;/param&gt;
      ''' &lt;returns&gt;0 on failure, non-zero on success&lt;/returns&gt;
      ''' &lt;remarks&gt;from http://support.microsoft.com/kb/147810 &lt;/remarks&gt;
      Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
           ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
           ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _
           ByVal ySrc As Long, ByVal dwRop As Long) As Long
  
      ''' &lt;summary&gt;
      ''' Grab a screen capture of the given control.
      ''' &lt;/summary&gt;
      ''' &lt;param name="control"&gt;control to grab&lt;/param&gt;
      ''' &lt;returns&gt;Bitmap image&lt;/returns&gt;
      ''' &lt;remarks&gt;used by mappoint map viewer and bing map viewer&lt;/remarks&gt;
      Public Shared Function ControlCapture(ByVal control As Control) As Bitmap
  
          'capture params
          Dim width As Integer = control.Width
          Dim height As Integer = control.Height
  
          'output object
          Dim bitmap As Bitmap = New Bitmap(width, height, PixelFormat.Format32bppArgb)
  
          'get handles to source and destination objects as graphics
          Dim sourceGraphics As Graphics = control.CreateGraphics()
          Dim destGrahpics As Graphics = Drawing.Graphics.FromImage(bitmap)
  
          'actual handles
          Dim sourceGraphicsPointer As System.IntPtr = sourceGraphics.GetHdc()
          Dim destGraphicsPointer As System.IntPtr = destGrahpics.GetHdc()
  
          'get references as ints
          Dim destAddress As Integer = destGraphicsPointer
          Dim sourceAddress As Integer = sourceGraphicsPointer
  
          'call win32 api
          BitBlt(destAddress, 0, 0, width, height, sourceAddress, 0, 0, Codes.SourceCopy)
  
          'clean up
          sourceGraphics.ReleaseHdc(sourceGraphicsPointer)
          destGrahpics.ReleaseHdc(destGraphicsPointer)
  
          Return bitmap
      End Function
  
      ''' &lt;summary&gt;
      ''' SRCCOPY(CC0020)      Copies the source bitmap to destination bitmap.
      ''' &lt;/summary&gt;
      ''' &lt;remarks&gt;From http://support.microsoft.com/kb/147810 &lt;/remarks&gt;
      Private Enum Codes
          SourceCopy = &amp;HCC0020
      End Enum
  
  End Class
  </code></pre>
  
  <p>Thanks,
  brian</p>