Skip to content

Instantly share code, notes, and snippets.

@hasherezade
Created August 19, 2022 23:59
Show Gist options
  • Save hasherezade/21d3938a3f846d988c1b030c3a713872 to your computer and use it in GitHub Desktop.
Save hasherezade/21d3938a3f846d988c1b030c3a713872 to your computer and use it in GitHub Desktop.
cmake_minimum_required (VERSION 3.0)
project (test_case2)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set (srcs
main.cpp
)
set (hdrs
)
add_library ( ${PROJECT_NAME} SHARED ${hdrs} ${srcs})
#include <Windows.h>
#include <stdio.h>
#include <string>
#include <mutex>
DWORD threadID;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL, "DLLMain :D!", "We've started.", 0);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
//extern "C" to prevent C++ name mangling
extern "C" __declspec(dllexport) BOOL SayGoodbye(LPVOID lpUserdata, DWORD nUserdataLen)
{
std::mutex testMutex;
try {
int i = 0, j = 1;
j /= i; // This will throw a SE (divide by zero).
}
catch (...) {
MessageBoxA(NULL, "C++ Exception Thrown!", "Caught it", 0);
}
MessageBoxA(NULL, "I'm Leaving!", "Goodbye", 0);
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment