Annotation of q_a/samples/simpldll/the_dll.c, revision 1.1

1.1     ! root        1: /************************************************************************\
        !             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: *
        !            28: \************************************************************************/
        !            29: 
        !            30: #include <windows.h>
        !            31: #include "the_dll.h"
        !            32: 
        !            33: 
        !            34: 
        !            35: /************************************************************************\
        !            36: *
        !            37: *  FUNCTION:    DLLEntryPoint
        !            38: *
        !            39: *  INPUTS:      hDLL       - handle of DLL
        !            40: *               dwReason   - indicates why DLL called
        !            41: *               lpReserved - reserved
        !            42: *
        !            43: *  RETURNS:     TRUE (always, in this example.)
        !            44: *
        !            45: *               Note that the retuRn value is used only when
        !            46: *               dwReason = DLL_PROCESS_ATTACH.
        !            47: *
        !            48: *               Normally the function would return TRUE if DLL initial-
        !            49: *               ization succeeded, or FALSE it it failed.
        !            50: *
        !            51: *  GLOBAL VARS: hMod - handle of DLL (initialized when PROCESS_ATTACHes)
        !            52: *
        !            53: *  COMMENTS:    The function will display a dialog box informing user of
        !            54: *               each notification message & the name of the attaching/
        !            55: *               detaching process/thread. For more information see
        !            56: *               "DLLEntryPoint" in the Win32 API reference.
        !            57: *
        !            58: \************************************************************************/
        !            59: 
        !            60: BOOL DLLEntryPoint (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
        !            61: { switch (dwReason)
        !            62:   { case DLL_PROCESS_ATTACH:
        !            63:     { char buf[BUFSIZE];
        !            64: 
        !            65:       /******************************************************************\
        !            66:       *  DLL is attaching to the address space of the current process.
        !            67:       \******************************************************************/
        !            68: 
        !            69:       hMod = hDLL;
        !            70:       GetModuleFileName (NULL, (LPTSTR) buf, BUFSIZE);
        !            71:       MessageBox (NULL, buf, "THE_DLL: Process attaching", MB_OK);
        !            72:       break;
        !            73:     }
        !            74:     case DLL_THREAD_ATTACH:
        !            75: 
        !            76:       /******************************************************************\
        !            77:       *  A new thread is being created in the current process.
        !            78:       \******************************************************************/
        !            79: 
        !            80:       MessageBox (NULL, "THE_DLL: Thread attaching", "", MB_OK);
        !            81:       break;
        !            82:     case DLL_THREAD_DETACH:
        !            83: 
        !            84:       /******************************************************************\
        !            85:       *  A thread is exiting cleanly.
        !            86:       \******************************************************************/
        !            87: 
        !            88:       MessageBox (NULL, "THE_DLL: Thread detaching", "", MB_OK);
        !            89:       break;
        !            90:     case DLL_PROCESS_DETACH:
        !            91: 
        !            92:       /******************************************************************\
        !            93:       *  The calling process is detaching the DLL from its address space.
        !            94:       \******************************************************************/
        !            95: 
        !            96:       MessageBox (NULL, "THE_DLL: Process detaching", "", MB_OK);
        !            97:       break;
        !            98:   }
        !            99:   return TRUE;
        !           100:   UNREFERENCED_PARAMETER(hDLL);
        !           101:   UNREFERENCED_PARAMETER(lpReserved);
        !           102: }
        !           103: 
        !           104: 
        !           105: 
        !           106: /************************************************************************\
        !           107: *
        !           108: *  FUNCTION: DLLFunction1
        !           109: *
        !           110: *  RETURNS:  1
        !           111: *
        !           112: \************************************************************************/
        !           113: 
        !           114: INT DLLFunction1 ()
        !           115: { MessageBeep (0);
        !           116:   return 1;
        !           117: }
        !           118: 
        !           119: 
        !           120: 
        !           121: /************************************************************************\
        !           122: *
        !           123: *  FUNCTION: DLLFunction2
        !           124: *
        !           125: *  INPUTS:   i - a dummy int param
        !           126: *
        !           127: *  RETURNS:  1
        !           128: *
        !           129: \************************************************************************/
        !           130: 
        !           131: INT DLLFunction2 (int i)
        !           132: { MessageBeep (0);
        !           133:   return 1;
        !           134:   UNREFERENCED_PARAMETER(i);
        !           135: }
        !           136: 
        !           137: 
        !           138: 
        !           139: /************************************************************************\
        !           140: *
        !           141: *  FUNCTION: DLLFunction3
        !           142: *
        !           143: *  INPUTS:   h - a dummy HANDLE param
        !           144: *
        !           145: *  RETURNS:  1
        !           146: *
        !           147: \************************************************************************/
        !           148: 
        !           149: INT DLLFunction3 (HANDLE h)
        !           150: { MessageBeep (0);
        !           151:   return 1;
        !           152:   UNREFERENCED_PARAMETER(h);
        !           153: }
        !           154: 
        !           155: 
        !           156: 
        !           157: /************************************************************************\
        !           158: *
        !           159: *  FUNCTION: DLLFunction4
        !           160: *
        !           161: *  INPUTS:   i - a dummy HWND param
        !           162: *
        !           163: *  RETURNS:  1
        !           164: *
        !           165: \************************************************************************/
        !           166: 
        !           167: INT DLLFunction4 (HWND hwnd)
        !           168: { MessageBeep (0);
        !           169:   return 1;
        !           170:   UNREFERENCED_PARAMETER(hwnd);
        !           171: }
        !           172: 
        !           173: 
        !           174: 
        !           175: /************************************************************************\
        !           176: *
        !           177: *  FUNCTION: DLLDialogBox
        !           178: *
        !           179: *  INPUTS:   hwndPArent - parent of the dialog box to display
        !           180: *
        !           181: *  RETURNS:  1
        !           182: *
        !           183: \************************************************************************/
        !           184: 
        !           185: INT DLLDialogBox (HWND hwndParent)
        !           186: { DialogBox (hMod, (LPTSTR) "DLLDlg", hwndParent, DLLDlgProc);
        !           187:   return 1;
        !           188: }
        !           189: 
        !           190: 
        !           191: 
        !           192: /************************************************************************\
        !           193: *
        !           194: *  FUNCTION: DLLDlgProc (standard dialog procedure INPUTS/RETURNS)
        !           195: *
        !           196: \************************************************************************/
        !           197: 
        !           198: BOOL DLLDlgProc (HWND hDlg, UINT msg, UINT wParam, LONG lParam)
        !           199: { switch (msg)
        !           200:   { case WM_INITDIALOG:
        !           201:       return (TRUE);
        !           202:     case WM_COMMAND:
        !           203:       EndDialog(hDlg, TRUE);
        !           204:       return (TRUE);
        !           205:   }
        !           206:   return (FALSE);
        !           207:   UNREFERENCED_PARAMETER(hDlg);
        !           208:   UNREFERENCED_PARAMETER(wParam);
        !           209:   UNREFERENCED_PARAMETER(lParam);
        !           210: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.