title: Build Windows DllMain DLL with CMake
body: <p>I have a question similar to <a href="https://stackoverflow.com/questions/29490489/create-a-windows-shared-library-with-dllmain-function-mingw-cmake">this one</a>. I am trying to compile a DLL for windows similar to how Visual Studio would, except with CLion and CMake. I've tried the answer in the question, as well as the steps shown <a href="https://cmake.org/Wiki/BuildingWinDLL" rel="nofollow noreferrer">here</a>, but I still get an error while injecting.</p>
  
  <p>My dll code is very simple, a similar dll compiled in visual studio works fine:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  void hello() {
      AllocConsole();
      freopen("CONOUT$", "w", stdout);
      cout &lt;&lt; "Hello, World!" &lt;&lt; endl;
  }
  
  bool __stdcall DllMain(HMODULE /*module*/, DWORD reason, LPVOID /*reserved*/) {
      if (reason == DLL_PROCESS_ATTACH) hello();
      return true;
  }
  </code></pre>
  
  <p>Also, here's what I tried in <code>CMakeLists.txt</code>: <strong>sorry, there should have been a space between PROJECT_NAME and MODULE</strong></p>
  
  <pre><code>cmake_minimum_required(VERSION 3.9)
  project(PROJECT_NAME)
  include (GenerateExportHeader)
  set(CMAKE_CXX_STANDARD 17)
  
  add_library(PROJECT_NAME MODULE main.cpp)
  set_target_properties(PROJECT_NAME PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
  GENERATE_EXPORT_HEADER(PROJECT_NAME
      BASE_NAME PROJECT_NAME
      EXPORT_MACRO_NAME PROJECT_NAME_EXPORT
      EXPORT_FILE_NAME PROJECT_NAME_Export.h
      STATIC_DEFINE PROJECT_NAME_BUILT_AS_STATIC)
  </code></pre>