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