title: using shell32 inside C++
body: <p>I am trying to use some code that uses the <code>IID_IShellDispatch</code> and <code>CLSID_Shell</code> constants.</p>
  
  <p>My includes:</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;WinDef.h&gt;
  #include &lt;Shellapi.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;ShlDisp.h&gt;
  #include &lt;Shlobj.h&gt;
  </code></pre>
  
  <p>The code:</p>
  
  <pre><code>    BSTR source = SysAllocString(input.toStdWString().c_str());
      BSTR dest = SysAllocString(outputDirectory.toStdWString().c_str());
      HRESULT result;
      IShellDispatch *pISD;
      Folder *folder = NULL;
      VARIANT vDir, vFile, vOpt;
  
      CoInitialize(NULL);
  
      result = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&amp;pISD);
      ...
  </code></pre>
  
  <p>The last line above throws error about undefined reference to CLSID_Shell and IID_IShellDispatch</p>
  
  <p>The code is part of a Qt project so I am using a Qt project file (for qmake) and I have added the <code>-lshell32</code> into the <code>LIBS</code> section of it:</p>
  
  <pre><code>LIBS += -lshell32 -loleaut32 -lole32
  </code></pre>
  
  <p>Command executed is</p>
  
  <pre><code>g++ -Wl,-subsystem,windows -mthreads -o debug\wallch.exe object_script.wallch.Debug  -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lshell32 -loleaut32 -lole32 -LC:\Qt\Qt5.2.0\5.2.0\mingw48_32\lib -lQt5Widgetsd -lQt5Networkd -lQt5Guid -lQt5Cored
  </code></pre>
  
  <p>Using MinGW on win7</p>