⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module.c

📁 一本已经绝版的好书
💻 C
字号:
/************************************************************
Module name: Module.C
Notices: Copyright (c) 1995-1997 Jeffrey Richter
************************************************************/


#include "..\CmnHdr.H"                  /* See Appendix C. */
#include <windows.h>

#define MODULEAPI __declspec(dllexport)
#include "Module.H"


/////////////////////////////////////////////////////////////


// Instruct the compiler to put the g_lModuleUsage data
// variable in its own data section, called Shared. We
// then instruct the linker that we want the data in this
// section to be shared by all instances of this application.
#pragma data_seg("Shared")
LONG g_lModuleUsage = 0;
#pragma data_seg()

// Instruct the linker to make the Shared section 
// readable, writable, and shared.
#pragma comment(linker, "/section:Shared,rws")


/////////////////////////////////////////////////////////////


// 'g_uMsgModCountChange' could be shared, but I chose not to.
UINT g_uMsgModCntChange = 0;


/////////////////////////////////////////////////////////////


BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason,
   LPVOID lpvReserved) {

   switch (fdwReason) {

   case DLL_PROCESS_ATTACH:
      // DLL is attaching to the address
      // space of the current process.

      // Increment this module's usage count when it is
      // attached to a process.
      InterlockedIncrement((PLONG) &g_lModuleUsage);

      // Reserve a systemwide window message for ourselves.
      // This message is used to notify all of the top-level
      // windows that this module's usage count has changed.
      g_uMsgModCntChange =
         RegisterWindowMessage(__TEXT("MsgModUsgCntChange"));

      // Notify all of the top-level windows that this
      // module's usage count has changed.
      PostMessage(HWND_BROADCAST, g_uMsgModCntChange, 0, 0);
      break;

   case DLL_THREAD_ATTACH:
      // A new thread is being created in the current process.
      break;

   case DLL_THREAD_DETACH:
      // A thread is exiting cleanly.
      break;

   case DLL_PROCESS_DETACH:
      // The calling process is detaching
      // the DLL from its address space.

      // Decrement this module's usage count when it
      // gets detached from a process.
      InterlockedDecrement((PLONG) &g_lModuleUsage);

      // Notify all of the top-level windows that this
      // module's usage count has changed.
      PostMessage(HWND_BROADCAST, g_uMsgModCntChange, 0, 0);

      break;
   }

   return(TRUE);
}


/////////////////////////////////////////////////////////////


MODULEAPI LONG GetModuleUsage (void) {
   return(g_lModuleUsage);
}


//////////////////////// End Of File ////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -