Compiling Visual Studio C++ code in Mingw32

118 views Asked by At

I am attempting to compile the .cpp file from this Github repo, using mingw32. In particular, I can compile .cpp file containing the code:

#include <windows.h>

extern "C" __declspec(dllexport)
DWORD WINAPI MessageBoxThread(LPVOID lpParam) {
  MessageBox(NULL, "Hello world!", "Hello World!", NULL);
  return 0;
}

extern "C" __declspec(dllexport)
BOOL APIENTRY DllMain(HMODULE hModule,
                      DWORD ul_reason_for_call,
                      LPVOID lpReserved) {
  switch (ul_reason_for_call) {
    case DLL_PROCESS_ATTACH:
      CreateThread(NULL, NULL, MessageBoxThread, NULL, NULL, NULL);
      break;
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
      break;
  }
  return TRUE;
}

using mingw32-g++ and the command:

i686-w64-mingw32-g++ hello-world.cpp -o hello-world.dll -shared

And it compiles with out errors. When I attempt to run the dll, using rundll32.exe hello-world.dll,MessageBoxThread, it doesn't work Even though the export function does exist (visible using 'dllexp.exe'). When I take the same code, via the solution in Visual Studio and compile it, the resulting dll binary works as intended.

Why does the above code not produce the same desired functionality using mingw32-g++ as it does for Visual Studio and how can I modify the above source code to compile with mingw32-g++?

0

There are 0 answers