--- q_a/samples/simpldll/linktest.c 2018/08/09 18:29:19 1.1 +++ q_a/samples/simpldll/linktest.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. +\******************************************************************************/ + +/******************************************************************************\ * * PROGRAM: LINKTEST.C * @@ -9,11 +20,12 @@ * for explicitly loading the DLL (via LoadLibrary()) at * runtime. * -* FUNTIONS: WinMain() - initialization, create window, msg loop -* MainWndProc() - processes main window msgs -* ThreadProc() - makes a single call into "THE_DLL.DLL" +* FUNTIONS: WinMain - initialization, create window, msg loop +* MainWndProc - processes main window msgs +* ThreadProc - makes a single call into "THE_DLL.DLL" +* AboutDlgProc- processes about dialog messages * -\************************************************************************/ +\******************************************************************************/ #include #include "linktest.h" @@ -21,25 +33,25 @@ -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: WinMain (standard WinMain INPUTS/RETURNS) * -* GLOBAL VARS: hwndMain - handle of main app window +* GLOBAL VARS: ghwndMain - handle of main app window * * LOCAL VARS: msg - msg to get/dispatch * -\************************************************************************/ +\******************************************************************************/ -int APIENTRY WinMain (HANDLE hInstance,HANDLE hPrevInstance, - LPSTR lpCmdLine, int nCmdShow) +int WINAPI WinMain (HANDLE hInstance,HANDLE hPrevInstance, + LPSTR lpCmdLine, int nCmdShow) { MSG msg; if (!hPrevInstance) { WNDCLASS wc; - wc.style = NULL; + wc.style = 0; wc.lpfnWndProc = (WNDPROC)MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; @@ -47,37 +59,39 @@ int APIENTRY WinMain (HANDLE hInstance,H wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = GetStockObject (WHITE_BRUSH); - wc.lpszMenuName = (LPSTR) "Menu"; - wc.lpszClassName = (LPSTR) "LINKTEST"; + wc.lpszMenuName = (LPCTSTR) "Menu"; + wc.lpszClassName = (LPCTSTR) "LINKTEST"; if (!RegisterClass (&wc)) - { MessageBox (NULL, "WinMain(): RegisterClass() failed", - "Err! - LINKTEST", MB_OK | MB_ICONHAND); + { + MessageBox (NULL, (LPCTSTR) "WinMain(): RegisterClass() failed", + (LPCTSTR) "Err! - LINKTEST", MB_OK | MB_ICONEXCLAMATION); return(FALSE); } } - if (!(hwndMain = CreateWindow ("LINKTEST", - "LINKTEST Sample Application", - WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, - CW_USEDEFAULT, CW_USEDEFAULT, - NULL, NULL, hInstance, NULL))) - return (NULL); - - ShowWindow(hwndMain, nCmdShow); - - while (GetMessage(&msg, NULL, NULL, NULL)) - { TranslateMessage(&msg); - DispatchMessage(&msg); + if (!(ghwndMain = CreateWindow ("LINKTEST", + "LINKTEST Sample Application", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + NULL, NULL, hInstance, NULL))) + return (0); + + ShowWindow (ghwndMain, nCmdShow); + + while (GetMessage (&msg, NULL, 0, 0)) + { + TranslateMessage (&msg); + DispatchMessage (&msg); } + return (msg.wParam); - UNREFERENCED_PARAMETER(lpCmdLine); } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: MainWndProc (standard window procedure INPUTS/RETURNS) * @@ -86,60 +100,114 @@ int APIENTRY WinMain (HANDLE hInstance,H * "THE_DLL.DLL". The "CreateThread" menuitem causes a thread * to be created- the thread then calls into "THE_DLL.DLL". * -\************************************************************************/ +\******************************************************************************/ + +LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam, + LPARAM lParam) +{ + switch (message) + { + case WM_COMMAND: -LONG APIENTRY MainWndProc (HWND hwnd, UINT message, UINT wParam, - LONG lParam) -{ switch (message) - { case WM_COMMAND: switch (LOWORD(wParam)) - { case IDM_CREATETHREAD: - { DWORD threadId; + { + case IDM_CREATETHREAD: + { + DWORD threadId; CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) ThreadProc, - NULL, NULL, &threadId); + NULL, 0, &threadId); break; } + case IDM_DLLFUNCTION1: + DLLFunction1 (); break; + case IDM_DLLFUNCTION2: + DLLFunction2 ((int) 0); break; + case IDM_DLLFUNCTION3: + DLLFunction3 ((HANDLE) NULL); break; + case IDM_DLLFUNCTION4: + DLLFunction4 ((HWND) NULL); break; + case IDM_DLLDIALOGBOX: + DLLDialogBox (hwnd); break; + + case IDM_ABOUT: + + DialogBox (GetModuleHandle (NULL), (LPCTSTR)"About", hwnd, + (DLGPROC) AboutDlgProc); + break; + default: + break; } break; + case WM_DESTROY: - PostQuitMessage(NULL); + + PostQuitMessage(0); break; + default: + return (DefWindowProc(hwnd, message, wParam, lParam)); } - return (NULL); + return (0); } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: Thread * -* GLOBAL VARS: hwndMain - handle of main app window +* GLOBAL VARS: ghwndMain - handle of main app window * -\************************************************************************/ +\******************************************************************************/ void ThreadProc () { - MessageBox (hwndMain, "calling DLLFunction1", "ThreadProc()", MB_OK); + MessageBox (ghwndMain, (LPCTSTR) "calling DLLFunction1", + (LPCTSTR) "ThreadProc()", MB_OK); DLLFunction1 (); } + + + +/******************************************************************************\ +* +* FUNCTION: AboutDlgProc (standard dialog procedure INPUTS/RETURNS) +* +* COMMENTS: Displays "about" message +* +\******************************************************************************/ + +LRESULT CALLBACK AboutDlgProc (HWND hwnd, UINT message, WPARAM wParam, + LPARAM lParam) +{ switch (message) + { + case WM_COMMAND: + + if (LOWORD(wParam) == IDOK) + { + EndDialog(hwnd, TRUE); + return (TRUE); + } + return (TRUE); + } + return (FALSE); +}