#include <stdio.h>
#include <windows.h>

BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved) {
  switch (fdwReason) {
  case DLL_PROCESS_ATTACH:
    fprintf(stderr,
            "DLL loaded into process. hinstDLL = %p, lpvReserved = %p\n",
            hInstDLL, lpvReserved);
    break;

  case DLL_THREAD_ATTACH:
    fprintf(stderr,
            "New thread created in the process using the DLL. "
            "hinstDLL = %p, lpvReserved = %p\n",
            hInstDLL, lpvReserved);
    break;

  case DLL_THREAD_DETACH:
    fprintf(stderr,
            "Thread using the DLL is terminating. hinstDLL = %p, "
            "lpvReserved = %p\n",
            hInstDLL, lpvReserved);
    break;

  case DLL_PROCESS_DETACH:
    fprintf(stderr,
            "DLL unloaded from process. hinstDLL = %p, lpvReserved = "
            "%p\n",
            hInstDLL, lpvReserved);
    break;
  }

  return TRUE;
}
