--- q_a/samples/simpldll/the_dll.c 2018/08/09 18:29:19 1.1.1.1 +++ q_a/samples/simpldll/the_dll.c 2018/08/09 18:29:49 1.1.1.3 @@ -1,4 +1,15 @@ -/************************************************************************\ + +/******************************************************************************\ +* This is a part of the Microsoft Source Code Samples. +* Copyright (C) 1993 Microsoft Corporation. +* All rights reserved. +* This source code is only intended as a supplement to +* Microsoft Development Tools and/or WinHelp documentation. +* See these sources for detailed information regarding the +* Microsoft samples programs. +\******************************************************************************/ + +/******************************************************************************\ * * MODULE: THE_DLL.C * @@ -9,7 +20,7 @@ * which loads a dialog template from the attached resource * file. * -* FUNCTIONS: DLLEntryPoint() - DLL entry point +* FUNCTIONS: DllMain() - DLL entry point * DLLFunction1() - skeleton function with no inputs * DLLFunction2() - skeleton function with int input * DLLFunction3() - skeleton function with HANDLE input @@ -18,23 +29,23 @@ * DLLDlgProc() - dialog window procedure * * COMMENTS: Another name may be used for the entry point -* ("DLLEntryPoint" is only an example). If no initialization +* ("DllMain" is only an example). If no initialization * or notification is required in a DLL, the DLL entry point * may be omitted. In either case, make sure to modify the -* "-entry:DLLEntryPoint" part of the DLL's link line in the +* "-entry:DllMain" part of the DLL's link line in the * makefile; either substitute the new entry point name, or * delete the line altogether (if omitting the entry point). * -\************************************************************************/ +\******************************************************************************/ #include #include "the_dll.h" -/************************************************************************\ +/******************************************************************************\ * -* FUNCTION: DLLEntryPoint +* FUNCTION: DllMain * * INPUTS: hDLL - handle of DLL * dwReason - indicates why DLL called @@ -48,77 +59,94 @@ * Normally the function would return TRUE if DLL initial- * ization succeeded, or FALSE it it failed. * -* GLOBAL VARS: hMod - handle of DLL (initialized when PROCESS_ATTACHes) +* GLOBAL VARS: ghMod - handle of DLL (initialized when PROCESS_ATTACHes) * * COMMENTS: The function will display a dialog box informing user of * each notification message & the name of the attaching/ * detaching process/thread. For more information see -* "DLLEntryPoint" in the Win32 API reference. +* "DllMain" in the Win32 API reference. * -\************************************************************************/ - -BOOL DLLEntryPoint (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved) -{ switch (dwReason) - { case DLL_PROCESS_ATTACH: - { char buf[BUFSIZE]; +\******************************************************************************/ - /******************************************************************\ - * DLL is attaching to the address space of the current process. - \******************************************************************/ +BOOL WINAPI DllMain (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved) +{ + switch (dwReason) + { + case DLL_PROCESS_ATTACH: + { + char buf[BUFSIZE+1]; + + // + // DLL is attaching to the address space of the current process. + // - hMod = hDLL; + ghMod = hDLL; GetModuleFileName (NULL, (LPTSTR) buf, BUFSIZE); - MessageBox (NULL, buf, "THE_DLL: Process attaching", MB_OK); + MessageBox ( GetFocus(), + (LPCTSTR) buf, + (LPCTSTR) "THE_DLL: Process attaching", + MB_OK | MB_SYSTEMMODAL); break; } - case DLL_THREAD_ATTACH: - /******************************************************************\ - * A new thread is being created in the current process. - \******************************************************************/ + case DLL_THREAD_ATTACH: - MessageBox (NULL, "THE_DLL: Thread attaching", "", MB_OK); + // + // A new thread is being created in the current process. + // + + MessageBox ( GetFocus(), + (LPCTSTR) "THE_DLL: Thread attaching", + (LPCTSTR) "", + MB_OK | MB_SYSTEMMODAL); break; - case DLL_THREAD_DETACH: - /******************************************************************\ - * A thread is exiting cleanly. - \******************************************************************/ + case DLL_THREAD_DETACH: - MessageBox (NULL, "THE_DLL: Thread detaching", "", MB_OK); + // + // A thread is exiting cleanly. + // + + MessageBox ( GetFocus(), + (LPCTSTR) "THE_DLL: Thread detaching", + (LPCTSTR) "", + MB_OK | MB_SYSTEMMODAL); break; - case DLL_PROCESS_DETACH: - /******************************************************************\ - * The calling process is detaching the DLL from its address space. - \******************************************************************/ + case DLL_PROCESS_DETACH: - MessageBox (NULL, "THE_DLL: Process detaching", "", MB_OK); + // + // The calling process is detaching the DLL from its address space. + // + MessageBox ( GetFocus(), + (LPCTSTR) "THE_DLL: Process detaching", + (LPCTSTR) "", + MB_OK | MB_SYSTEMMODAL ); break; } - return TRUE; - UNREFERENCED_PARAMETER(hDLL); - UNREFERENCED_PARAMETER(lpReserved); + +return TRUE; } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: DLLFunction1 * * RETURNS: 1 * -\************************************************************************/ +\******************************************************************************/ INT DLLFunction1 () -{ MessageBeep (0); +{ + MessageBeep (0); return 1; } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: DLLFunction2 * @@ -126,17 +154,17 @@ INT DLLFunction1 () * * RETURNS: 1 * -\************************************************************************/ +\******************************************************************************/ INT DLLFunction2 (int i) -{ MessageBeep (0); +{ + MessageBeep (0); return 1; - UNREFERENCED_PARAMETER(i); } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: DLLFunction3 * @@ -144,17 +172,17 @@ INT DLLFunction2 (int i) * * RETURNS: 1 * -\************************************************************************/ +\******************************************************************************/ INT DLLFunction3 (HANDLE h) -{ MessageBeep (0); +{ + MessageBeep (0); return 1; - UNREFERENCED_PARAMETER(h); } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: DLLFunction4 * @@ -162,17 +190,17 @@ INT DLLFunction3 (HANDLE h) * * RETURNS: 1 * -\************************************************************************/ +\******************************************************************************/ INT DLLFunction4 (HWND hwnd) -{ MessageBeep (0); +{ + MessageBeep (0); return 1; - UNREFERENCED_PARAMETER(hwnd); } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: DLLDialogBox * @@ -180,31 +208,30 @@ INT DLLFunction4 (HWND hwnd) * * RETURNS: 1 * -\************************************************************************/ +\******************************************************************************/ INT DLLDialogBox (HWND hwndParent) -{ DialogBox (hMod, (LPTSTR) "DLLDlg", hwndParent, DLLDlgProc); +{ + DialogBox (ghMod, (LPCTSTR) "DLLDlg", hwndParent, (DLGPROC) DLLDlgProc); return 1; } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: DLLDlgProc (standard dialog procedure INPUTS/RETURNS) * -\************************************************************************/ +\******************************************************************************/ -BOOL DLLDlgProc (HWND hDlg, UINT msg, UINT wParam, LONG lParam) -{ switch (msg) - { case WM_INITDIALOG: - return (TRUE); +LRESULT CALLBACK DLLDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { case WM_COMMAND: + EndDialog(hDlg, TRUE); return (TRUE); } return (FALSE); - UNREFERENCED_PARAMETER(hDlg); - UNREFERENCED_PARAMETER(wParam); - UNREFERENCED_PARAMETER(lParam); }