title: WinAPI SetupDiGetClassDevs seg faults in wxWidgets app unless called from static method
body: <p>This static class method works perfectly</p>
  
  <pre><code>class cHID
  {
  public:
      static void TestStatic();
  };
  
  void cHID::TestStatic()
  {
      GUID HID_GUID;
      HidD_GetHidGuid( &amp; HID_GUID );
      HDEVINFO DeviceInfoSet = SetupDiGetClassDevs(
                                   &amp;HID_GUID,
                                   NULL,NULL,
                                   DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
      if (DeviceInfoSet)
      {
          SetupDiDestroyDeviceInfoList(DeviceInfoSet);
      }
  }
  
  cHID::TestStatic();
  //cHID theHID;
  //theHid.Test2();
  </code></pre>
  
  <p>However, the identical code in a non-static method segment faults inside SetupDiGetClassDevs()</p>
  
  <pre><code>class cHID
  {
  public:
      void Test2();
  };
  
  void cHID::Test2()
  {
      GUID HID_GUID;
      HidD_GetHidGuid( &amp; HID_GUID );
      HDEVINFO DeviceInfoSet = SetupDiGetClassDevs(
                                   &amp;HID_GUID,
                                   NULL,NULL,
                                   DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
      if (DeviceInfoSet)
      {
          SetupDiDestroyDeviceInfoList(DeviceInfoSet);
      }
  }
  
  //cHID::TestStatic();
  cHID theHID;
  theHid.Test2();
  </code></pre>
  
  <p>I would much prefer calling SetupDiGetClassDevs from a non static method, so I can save some results in class attributes.</p>
  
  <p>This is a wxWidgets "hello world" program. I copy it to a console program and both methods to work. So wxWidgets isn't playing nicely with SetupDiGetClassDevs?</p>
  
  <p>Here is the complete failing wxWidgets program</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;stdexcept&gt;
  
  #include &lt;wx/wx.h&gt;
  #include &lt;wx/app.h&gt;
  #include &lt;wx/textdlg.h&gt;
  
  #include &lt;setupapi.h&gt;
  #include &lt;ddk/hidsdi.h&gt;
  
  class cHID
  {
  public:
  
      void Test1();
      static void TestStatic();
  };
  
  
  class cApp : public wxApp
  {
  public:
      virtual bool OnInit();
  
  };
  
  class cFrame: public wxFrame
  {
  public:
      cHID theHID;
  
      cFrame(wxFrame *frame, const wxString&amp; title)
          : wxFrame(frame, -1, title, wxPoint(-1,-1),wxSize(600,600))
      {
      //    cHID::TestStatic();
              cHID theHID;
              theHID.Test1();
  
      }
  };
  
  IMPLEMENT_APP(cApp);
  
  bool cApp::OnInit()
  {
      cFrame* frame = new cFrame(0L, "HIDGraph");
      frame-&gt;Show();
  
      return true;
  }
  
  void cHID::Test1()
  {
      GUID HID_GUID;
      HidD_GetHidGuid( &amp; HID_GUID );
      HDEVINFO DeviceInfoSet = SetupDiGetClassDevs(
                                   &amp;HID_GUID,
                                   NULL,NULL,
                                   DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
      if (DeviceInfoSet)
      {
          SetupDiDestroyDeviceInfoList(DeviceInfoSet);
      }
  }
  void cHID::TestStatic()
  {
      GUID HID_GUID;
      HidD_GetHidGuid( &amp; HID_GUID );
      HDEVINFO DeviceInfoSet = SetupDiGetClassDevs(
                                   &amp;HID_GUID,
                                   NULL,NULL,
                                   DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
      if (DeviceInfoSet)
      {
          SetupDiDestroyDeviceInfoList(DeviceInfoSet);
      }
  }
  </code></pre>
  
  <p>Here is the complete passing console program</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;ddk/hidsdi.h&gt;
  #include &lt;setupapi.h&gt;
  
  using namespace std;
  
  class cHID
  {
  public:
      static void TestStatic();
      void Test2();
  };
  
  void cHID::TestStatic()
  {
      GUID HID_GUID;
      HidD_GetHidGuid( &amp; HID_GUID );
      HDEVINFO DeviceInfoSet = SetupDiGetClassDevs(
                                   &amp;HID_GUID,
                                   NULL,NULL,
                                   DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
      if (DeviceInfoSet)
      {
          SetupDiDestroyDeviceInfoList(DeviceInfoSet);
      }
  }
  
  void cHID::Test2()
  {
      GUID HID_GUID;
      HidD_GetHidGuid( &amp; HID_GUID );
      HDEVINFO DeviceInfoSet = SetupDiGetClassDevs(
                                   &amp;HID_GUID,
                                   NULL,NULL,
                                   DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
      if (DeviceInfoSet)
      {
          SetupDiDestroyDeviceInfoList(DeviceInfoSet);
      }
  }
  
  int main()
  {
  //cHID::TestStatic();
      cHID theHID;
      theHID.Test2();
  
      return 0;
  }
  </code></pre>