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

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

unix.superglobalmegacorp.com

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