|
|
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: * PROGRAM: LINKTEST.C 15: * 16: * PURPOSE: A simple demonstration of an executable file linking 17: * with and calling into a DLL we created. This necessitates 18: * the creation of a .LIB file for the DLL, which is used 19: * when linking the .EXE. Doing this eliminates the need 20: * for explicitly loading the DLL (via LoadLibrary()) at 21: * runtime. 22: * 1.1.1.2 root 23: * FUNTIONS: WinMain - initialization, create window, msg loop 24: * MainWndProc - processes main window msgs 25: * ThreadProc - makes a single call into "THE_DLL.DLL" 26: * AboutDlgProc- processes about dialog messages 1.1 root 27: * 1.1.1.2 root 28: \******************************************************************************/ 1.1 root 29: 30: #include <windows.h> 31: #include "linktest.h" 32: #include "the_dll.h" 33: 34: 35: 1.1.1.2 root 36: /******************************************************************************\ 1.1 root 37: * 38: * FUNCTION: WinMain (standard WinMain INPUTS/RETURNS) 39: * 1.1.1.2 root 40: * GLOBAL VARS: ghwndMain - handle of main app window 1.1 root 41: * 42: * LOCAL VARS: msg - msg to get/dispatch 43: * 1.1.1.2 root 44: \******************************************************************************/ 1.1 root 45: 1.1.1.2 root 46: int WINAPI WinMain (HANDLE hInstance,HANDLE hPrevInstance, 47: LPSTR lpCmdLine, int nCmdShow) 1.1 root 48: { MSG msg; 49: 50: if (!hPrevInstance) 51: { 52: WNDCLASS wc; 53: 1.1.1.3 ! root 54: wc.style = 0; 1.1 root 55: wc.lpfnWndProc = (WNDPROC)MainWndProc; 56: wc.cbClsExtra = 0; 57: wc.cbWndExtra = 0; 58: wc.hInstance = hInstance; 59: wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 60: wc.hCursor = LoadCursor (NULL, IDC_ARROW); 61: wc.hbrBackground = GetStockObject (WHITE_BRUSH); 1.1.1.2 root 62: wc.lpszMenuName = (LPCTSTR) "Menu"; 63: wc.lpszClassName = (LPCTSTR) "LINKTEST"; 1.1 root 64: 65: if (!RegisterClass (&wc)) 1.1.1.2 root 66: { 67: MessageBox (NULL, (LPCTSTR) "WinMain(): RegisterClass() failed", 68: (LPCTSTR) "Err! - LINKTEST", MB_OK | MB_ICONEXCLAMATION); 1.1 root 69: return(FALSE); 70: } 71: } 72: 1.1.1.2 root 73: if (!(ghwndMain = CreateWindow ("LINKTEST", 74: "LINKTEST Sample Application", 75: WS_OVERLAPPEDWINDOW, 76: CW_USEDEFAULT, CW_USEDEFAULT, 77: CW_USEDEFAULT, CW_USEDEFAULT, 78: NULL, NULL, hInstance, NULL))) 1.1.1.3 ! root 79: return (0); 1.1 root 80: 1.1.1.2 root 81: ShowWindow (ghwndMain, nCmdShow); 1.1 root 82: 1.1.1.3 ! root 83: while (GetMessage (&msg, NULL, 0, 0)) 1.1.1.2 root 84: { 85: TranslateMessage (&msg); 86: DispatchMessage (&msg); 1.1 root 87: } 1.1.1.2 root 88: 1.1 root 89: return (msg.wParam); 90: } 91: 92: 93: 1.1.1.2 root 94: /******************************************************************************\ 1.1 root 95: * 96: * FUNCTION: MainWndProc (standard window procedure INPUTS/RETURNS) 97: * 98: * COMMENTS: Menuitems IDM_DLLFUNCTION1 through IDM_DLLDIALOGBOX are 99: * all processed by calling their respective functions in 100: * "THE_DLL.DLL". The "CreateThread" menuitem causes a thread 101: * to be created- the thread then calls into "THE_DLL.DLL". 102: * 1.1.1.2 root 103: \******************************************************************************/ 104: 105: LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam, 106: LPARAM lParam) 107: { 108: switch (message) 109: { 110: case WM_COMMAND: 1.1 root 111: 112: switch (LOWORD(wParam)) 1.1.1.2 root 113: { 114: case IDM_CREATETHREAD: 115: { 116: DWORD threadId; 1.1 root 117: 118: CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) ThreadProc, 1.1.1.3 ! root 119: NULL, 0, &threadId); 1.1 root 120: break; 121: } 1.1.1.2 root 122: 1.1 root 123: case IDM_DLLFUNCTION1: 1.1.1.2 root 124: 1.1 root 125: DLLFunction1 (); 126: break; 1.1.1.2 root 127: 1.1 root 128: case IDM_DLLFUNCTION2: 1.1.1.2 root 129: 1.1 root 130: DLLFunction2 ((int) 0); 131: break; 1.1.1.2 root 132: 1.1 root 133: case IDM_DLLFUNCTION3: 1.1.1.2 root 134: 1.1 root 135: DLLFunction3 ((HANDLE) NULL); 136: break; 1.1.1.2 root 137: 1.1 root 138: case IDM_DLLFUNCTION4: 1.1.1.2 root 139: 1.1 root 140: DLLFunction4 ((HWND) NULL); 141: break; 1.1.1.2 root 142: 1.1 root 143: case IDM_DLLDIALOGBOX: 1.1.1.2 root 144: 1.1 root 145: DLLDialogBox (hwnd); 146: break; 1.1.1.2 root 147: 148: case IDM_ABOUT: 149: 150: DialogBox (GetModuleHandle (NULL), (LPCTSTR)"About", hwnd, 151: (DLGPROC) AboutDlgProc); 152: break; 153: 1.1 root 154: default: 1.1.1.2 root 155: 1.1 root 156: break; 157: } 158: break; 1.1.1.2 root 159: 1.1 root 160: case WM_DESTROY: 1.1.1.2 root 161: 1.1.1.3 ! root 162: PostQuitMessage(0); 1.1 root 163: break; 1.1.1.2 root 164: 1.1 root 165: default: 1.1.1.2 root 166: 1.1 root 167: return (DefWindowProc(hwnd, message, wParam, lParam)); 168: } 1.1.1.3 ! root 169: return (0); 1.1 root 170: } 171: 172: 173: 1.1.1.2 root 174: /******************************************************************************\ 1.1 root 175: * 176: * FUNCTION: Thread 177: * 1.1.1.2 root 178: * GLOBAL VARS: ghwndMain - handle of main app window 1.1 root 179: * 1.1.1.2 root 180: \******************************************************************************/ 1.1 root 181: 182: void ThreadProc () 183: { 1.1.1.2 root 184: MessageBox (ghwndMain, (LPCTSTR) "calling DLLFunction1", 185: (LPCTSTR) "ThreadProc()", MB_OK); 1.1 root 186: DLLFunction1 (); 187: } 1.1.1.2 root 188: 189: 190: 191: /******************************************************************************\ 192: * 193: * FUNCTION: AboutDlgProc (standard dialog procedure INPUTS/RETURNS) 194: * 195: * COMMENTS: Displays "about" message 196: * 197: \******************************************************************************/ 198: 199: LRESULT CALLBACK AboutDlgProc (HWND hwnd, UINT message, WPARAM wParam, 200: LPARAM lParam) 201: { switch (message) 202: { 203: case WM_COMMAND: 204: 205: if (LOWORD(wParam) == IDOK) 206: { 207: EndDialog(hwnd, TRUE); 208: return (TRUE); 209: } 210: return (TRUE); 211: } 212: return (FALSE); 213: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.