|
|
1.1.1.2 ! root 1: /******************************************************************************\ 1.1 root 2: * 3: * MODULE: THE_DLL.C 4: * 5: * PURPOSE: To provide a simple DLL template. This module contains a 6: * generic DLL entry point (replacing the LIbMain & WEP of 7: * Win16), four exported skeleton functions with varying 8: * parameter lists, and one exported "DLLDialogBox" function 9: * which loads a dialog template from the attached resource 10: * file. 11: * 12: * FUNCTIONS: DLLEntryPoint() - DLL entry point 13: * DLLFunction1() - skeleton function with no inputs 14: * DLLFunction2() - skeleton function with int input 15: * DLLFunction3() - skeleton function with HANDLE input 16: * DLLFunction4() - skeleton function with HWND input 17: * DLLDialogBox() - calls DialogBox using hndParent param 18: * DLLDlgProc() - dialog window procedure 19: * 20: * COMMENTS: Another name may be used for the entry point 21: * ("DLLEntryPoint" is only an example). If no initialization 22: * or notification is required in a DLL, the DLL entry point 23: * may be omitted. In either case, make sure to modify the 24: * "-entry:DLLEntryPoint" part of the DLL's link line in the 25: * makefile; either substitute the new entry point name, or 26: * delete the line altogether (if omitting the entry point). 27: * 1.1.1.2 ! root 28: * ! 29: * Microsoft Developer Support ! 30: * Copyright (c) 1992 Microsoft Corporation ! 31: * ! 32: \******************************************************************************/ 1.1 root 33: 34: #include <windows.h> 35: #include "the_dll.h" 36: 37: 38: 1.1.1.2 ! root 39: /******************************************************************************\ 1.1 root 40: * 41: * FUNCTION: DLLEntryPoint 42: * 43: * INPUTS: hDLL - handle of DLL 44: * dwReason - indicates why DLL called 45: * lpReserved - reserved 46: * 47: * RETURNS: TRUE (always, in this example.) 48: * 49: * Note that the retuRn value is used only when 50: * dwReason = DLL_PROCESS_ATTACH. 51: * 52: * Normally the function would return TRUE if DLL initial- 53: * ization succeeded, or FALSE it it failed. 54: * 1.1.1.2 ! root 55: * GLOBAL VARS: ghMod - handle of DLL (initialized when PROCESS_ATTACHes) 1.1 root 56: * 57: * COMMENTS: The function will display a dialog box informing user of 58: * each notification message & the name of the attaching/ 59: * detaching process/thread. For more information see 60: * "DLLEntryPoint" in the Win32 API reference. 61: * 1.1.1.2 ! root 62: \******************************************************************************/ 1.1 root 63: 1.1.1.2 ! root 64: BOOL WINAPI DLLEntryPoint (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved) ! 65: { ! 66: switch (dwReason) ! 67: { ! 68: case DLL_PROCESS_ATTACH: ! 69: { ! 70: char buf[BUFSIZE]; ! 71: ! 72: // ! 73: // DLL is attaching to the address space of the current process. ! 74: // 1.1 root 75: 1.1.1.2 ! root 76: ghMod = hDLL; 1.1 root 77: GetModuleFileName (NULL, (LPTSTR) buf, BUFSIZE); 1.1.1.2 ! root 78: MessageBox (NULL, (LPCTSTR) buf, (LPCTSTR) "THE_DLL: Process attaching", ! 79: MB_OK); 1.1 root 80: break; 81: } 1.1.1.2 ! root 82: 1.1 root 83: case DLL_THREAD_ATTACH: 84: 1.1.1.2 ! root 85: // ! 86: // A new thread is being created in the current process. ! 87: // 1.1 root 88: 1.1.1.2 ! root 89: MessageBox (NULL, (LPCTSTR) "THE_DLL: Thread attaching", (LPCTSTR) "", ! 90: MB_OK); 1.1 root 91: break; 1.1.1.2 ! root 92: 1.1 root 93: case DLL_THREAD_DETACH: 94: 1.1.1.2 ! root 95: // ! 96: // A thread is exiting cleanly. ! 97: // 1.1 root 98: 1.1.1.2 ! root 99: MessageBox (NULL, (LPCTSTR) "THE_DLL: Thread detaching", (LPCTSTR) "", ! 100: MB_OK); 1.1 root 101: break; 1.1.1.2 ! root 102: 1.1 root 103: case DLL_PROCESS_DETACH: 104: 1.1.1.2 ! root 105: // ! 106: // The calling process is detaching the DLL from its address space. ! 107: // 1.1 root 108: 1.1.1.2 ! root 109: MessageBox (NULL, (LPCTSTR) "THE_DLL: Process detaching", (LPCTSTR) "", ! 110: MB_OK); 1.1 root 111: break; 112: } 1.1.1.2 ! root 113: 1.1 root 114: return TRUE; 115: } 116: 117: 118: 1.1.1.2 ! root 119: /******************************************************************************\ 1.1 root 120: * 121: * FUNCTION: DLLFunction1 122: * 123: * RETURNS: 1 124: * 1.1.1.2 ! root 125: \******************************************************************************/ 1.1 root 126: 127: INT DLLFunction1 () 1.1.1.2 ! root 128: { ! 129: MessageBeep (0); 1.1 root 130: return 1; 131: } 132: 133: 134: 1.1.1.2 ! root 135: /******************************************************************************\ 1.1 root 136: * 137: * FUNCTION: DLLFunction2 138: * 139: * INPUTS: i - a dummy int param 140: * 141: * RETURNS: 1 142: * 1.1.1.2 ! root 143: \******************************************************************************/ 1.1 root 144: 145: INT DLLFunction2 (int i) 1.1.1.2 ! root 146: { ! 147: MessageBeep (0); 1.1 root 148: return 1; 149: } 150: 151: 152: 1.1.1.2 ! root 153: /******************************************************************************\ 1.1 root 154: * 155: * FUNCTION: DLLFunction3 156: * 157: * INPUTS: h - a dummy HANDLE param 158: * 159: * RETURNS: 1 160: * 1.1.1.2 ! root 161: \******************************************************************************/ 1.1 root 162: 163: INT DLLFunction3 (HANDLE h) 1.1.1.2 ! root 164: { ! 165: MessageBeep (0); 1.1 root 166: return 1; 167: } 168: 169: 170: 1.1.1.2 ! root 171: /******************************************************************************\ 1.1 root 172: * 173: * FUNCTION: DLLFunction4 174: * 175: * INPUTS: i - a dummy HWND param 176: * 177: * RETURNS: 1 178: * 1.1.1.2 ! root 179: \******************************************************************************/ 1.1 root 180: 181: INT DLLFunction4 (HWND hwnd) 1.1.1.2 ! root 182: { ! 183: MessageBeep (0); 1.1 root 184: return 1; 185: } 186: 187: 188: 1.1.1.2 ! root 189: /******************************************************************************\ 1.1 root 190: * 191: * FUNCTION: DLLDialogBox 192: * 193: * INPUTS: hwndPArent - parent of the dialog box to display 194: * 195: * RETURNS: 1 196: * 1.1.1.2 ! root 197: \******************************************************************************/ 1.1 root 198: 199: INT DLLDialogBox (HWND hwndParent) 1.1.1.2 ! root 200: { ! 201: DialogBox (ghMod, (LPCTSTR) "DLLDlg", hwndParent, (DLGPROC) DLLDlgProc); 1.1 root 202: return 1; 203: } 204: 205: 206: 1.1.1.2 ! root 207: /******************************************************************************\ 1.1 root 208: * 209: * FUNCTION: DLLDlgProc (standard dialog procedure INPUTS/RETURNS) 210: * 1.1.1.2 ! root 211: \******************************************************************************/ 1.1 root 212: 1.1.1.2 ! root 213: LRESULT CALLBACK DLLDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) ! 214: { ! 215: switch (msg) ! 216: { 1.1 root 217: case WM_COMMAND: 1.1.1.2 ! root 218: 1.1 root 219: EndDialog(hDlg, TRUE); 220: return (TRUE); 221: } 222: return (FALSE); 223: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.