I apologise if this has already been asked, but I have been trying to find an answer for many weeks now.
I am not particularly competent when it comes to shared libraries, however, using CLion RC 1.0
(and its integrated CMake) with MinGW
, I have been unable to create a functional Windows DLL
with a DllMain
function. I did manage to create a .dll
file, but it quickly became apparent that the symbol did not export corrrectly.
Simply put, I would like to see identical or similar behaviour to what is obtained with Visual Studio's default Win32 DLL template.
CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
project(DllMainTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_library(DllMainTest SHARED ${SOURCE_FILES})
main.cpp
#include <windows.h>
extern "C" BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved
) {
switch(fdwReason) {
case DLL_PROCESS_ATTACH:
MessageBox(NULL, "It works!", "Status", MB_OK);
case DLL_PROCESS_DETACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
default:
break;
}
return TRUE;
}
EDIT: The intention for this DLL is to have it injected into a 32-bit process and for it to display a MessageBox on load.