title: CBitmap::LoadBitmap() refuses to load a resource
body: <p>I am working on a DLL which contains a bitmap resource. I imported that bitmap through the Resource View in Visual Studio. The DLL also exports a class which has a function that tries to load the bitmap:</p>
  
  <pre><code>BOOL CMyExportedClass::Create(CWnd* pParentWnd /*= NULL*/)
  {
      if (!m_bitmap.LoadBitmap(IDB_BITMAP1))
          return FALSE;
      // ...
  }
  </code></pre>
  
  <p>From an MFC application I load the DLL. Inside the applications <code>InitInstance()</code> function I then invoke an exported function of the DLL which eventually calls <code>CMyExportedClass::Create()</code>.</p>
  
  <p>However, <code>LoadBitmap()</code> always returns <code>0</code>, which according to the <a href="http://msdn.microsoft.com/en-us/library/wc99t364.aspx" rel="nofollow">documentation</a> indicates either insufficient memory (not the case) or that the resource does not exist.</p>
  
  <p>The bitmap file is part of my DLL project and <code>IDB_BITMAP1</code> is defined in the <em>.rc</em> file as well as in <em>resource.h</em>:</p>
  
  <p><strong>MyDLL.rc:</strong></p>
  
  <pre><code>IDB_BITMAP1             BITMAP                  "res\\mybitmap.bmp"
  </code></pre>
  
  <p><strong>resource.h:</strong></p>
  
  <pre><code>#define IDB_BITMAP1                     1034
  </code></pre>
  
  <p>I already checked that the ID has been defined only once. FWIW: At the time <code>LoadBitmap()</code> is invoked, the DLLs <code>InitiInstance()</code> function has already returned successfully.</p>
  
  <p>What are possible reasons why <code>LoadBitmap()</code> refuses to load the resource and how can I fix this?</p>
  
  <p><hr/>
  <strong>Edit:</strong><br/>
  I can successfully load the resource if instead of <code>m_bitmap.LoadBitmap(IDB_BITMAP1)</code> I do the following:</p>
  
  <pre><code>HBITMAP hBitmap = (HBITMAP)LoadImage(hCurrentModule, MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, 0);
  if(hBitmap)
      m_bitmap.Attach((HBITMAP)hBitmap);
  </code></pre>
  
  <p>So what's the difference between <code>CBitmap::LoadBitmap()</code> and the <code>LoadImage()</code> functions here?</p>