title: C++: Properly using the LoadImage and SetCursor functions
body: <p>I am trying to write a quick and simple C++ program that changes the cursor icon to a custom image from a directory. The Windows Dev Center seems to have <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms646970(v=vs.85).aspx" rel="nofollow">some fairly straightforward documentation on how to do this in C++</a>, from which I came up with this code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;chrono&gt;
  #include &lt;thread&gt;
  #include &lt;Windows.h&gt;
  
  using namespace std;
  
  int main(int argc, char** argv)
  {
      //HINSTANCE hInst = GetModuleHandle(NULL);
      HINSTANCE hInst = NULL;
      HCURSOR cursor = (HCURSOR)LoadImage(hInst, "Image.bmp", IMAGE_BITMAP,
                       32, 32, LR_LOADFROMFILE); //Also tried LR_SHARED
      cout &lt;&lt; "Initializing\n";
      Sleep(1500);
      SetCursor(cursor);
      //Also tried SetSystemCursor(cursor, 32512);
      cout &lt;&lt; "Setting cursor\n";
      Sleep(1500);
      DestroyCursor(cursor);
      cout &lt;&lt; "Restoring cursor\n";   
      Sleep(2000);
      return 0;
  }
  </code></pre>
  
  <p>The program should change the cursor to the bitmap image, then change it back, then exit. The messages get printed when I run it, but the cursor doesn't change like it should. I'm not entirely sure whether my problem lies with the LoadImage function, with the SetCursor function, or with something else. I've tried various types of HINSTANCEs for the HINSTANCE parameter of the LoadImage function, I've tried different flags for the last argument for the LoadImage function, and I've also tried using the SetSystemCursor function instead of the SetCursor function.</p>
  
  <p>All I want to do is change the mouse cursor image. It seems like this should be really simple, but it turns out to be more complicated than I thought. My intent is to export this code as a DLL to use with the Java Native Interface for a Java project I'm using since the JVM can't change the cursor outside of the program window.</p>
  
  <p>I've searched all over the place and saw some slightly similar questions here, but none that properly addressed the issue I'm having. I have seen some people mention that I need to call the SetCursor function in response to a WM_SETCURSOR message, but I'm not quite sure what they mean (I don't have much C++ experience, so please bear with me). I hope you guys can help me. Thanks.</p>