Annotation of q_a/samples/simpldll/linktest.c, revision 1.1.1.1

1.1       root        1: /************************************************************************\
                      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: *
                     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: *
                     16: \************************************************************************/
                     17: 
                     18: #include <windows.h>
                     19: #include "linktest.h"
                     20: #include "the_dll.h"
                     21: 
                     22: 
                     23: 
                     24: /************************************************************************\
                     25: *
                     26: *  FUNCTION:    WinMain (standard WinMain INPUTS/RETURNS)
                     27: *
                     28: *  GLOBAL VARS: hwndMain - handle of main app window
                     29: *
                     30: *  LOCAL VARS:  msg - msg to get/dispatch
                     31: *
                     32: \************************************************************************/
                     33: 
                     34: int APIENTRY WinMain (HANDLE hInstance,HANDLE hPrevInstance,
                     35:                       LPSTR lpCmdLine, int nCmdShow)
                     36: { MSG msg;
                     37: 
                     38:   if (!hPrevInstance)
                     39:   {
                     40:     WNDCLASS wc;
                     41: 
                     42:     wc.style         = NULL;
                     43:     wc.lpfnWndProc   = (WNDPROC)MainWndProc;
                     44:     wc.cbClsExtra    = 0;
                     45:     wc.cbWndExtra    = 0;
                     46:     wc.hInstance     = hInstance;
                     47:     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
                     48:     wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
                     49:     wc.hbrBackground = GetStockObject (WHITE_BRUSH);
                     50:     wc.lpszMenuName  = (LPSTR) "Menu";
                     51:     wc.lpszClassName = (LPSTR) "LINKTEST";
                     52: 
                     53:     if (!RegisterClass (&wc))
                     54:     { MessageBox (NULL, "WinMain(): RegisterClass() failed",
                     55:                   "Err! - LINKTEST", MB_OK | MB_ICONHAND);
                     56:       return(FALSE);
                     57:     }
                     58:   }
                     59: 
                     60:   if (!(hwndMain = CreateWindow ("LINKTEST",
                     61:                                  "LINKTEST Sample Application",
                     62:                                  WS_OVERLAPPEDWINDOW,
                     63:                                  CW_USEDEFAULT, CW_USEDEFAULT,
                     64:                                  CW_USEDEFAULT, CW_USEDEFAULT,
                     65:                                  NULL, NULL, hInstance, NULL)))
                     66:     return (NULL);
                     67: 
                     68:   ShowWindow(hwndMain, nCmdShow);
                     69: 
                     70:   while (GetMessage(&msg, NULL, NULL, NULL))
                     71:   { TranslateMessage(&msg);
                     72:     DispatchMessage(&msg);
                     73:   }
                     74:   return (msg.wParam);
                     75:   UNREFERENCED_PARAMETER(lpCmdLine);
                     76: }
                     77: 
                     78: 
                     79: 
                     80: /************************************************************************\
                     81: *
                     82: *  FUNCTION:    MainWndProc (standard window procedure INPUTS/RETURNS)
                     83: *
                     84: *  COMMENTS:    Menuitems IDM_DLLFUNCTION1 through IDM_DLLDIALOGBOX are
                     85: *               all processed by calling their respective functions in
                     86: *               "THE_DLL.DLL". The "CreateThread" menuitem causes a thread
                     87: *               to be created- the thread then calls into "THE_DLL.DLL".
                     88: *
                     89: \************************************************************************/
                     90: 
                     91: LONG APIENTRY MainWndProc (HWND hwnd, UINT message, UINT wParam,
                     92:                            LONG lParam)
                     93: { switch (message)
                     94:   { case WM_COMMAND:
                     95:       switch (LOWORD(wParam))
                     96:       { case IDM_CREATETHREAD:
                     97:         { DWORD  threadId;
                     98: 
                     99:           CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) ThreadProc,
                    100:                         NULL, NULL, &threadId);
                    101:           break;
                    102:         }
                    103:         case IDM_DLLFUNCTION1:
                    104:           DLLFunction1 ();
                    105:           break;
                    106:         case IDM_DLLFUNCTION2:
                    107:           DLLFunction2 ((int) 0);
                    108:           break;
                    109:         case IDM_DLLFUNCTION3:
                    110:           DLLFunction3 ((HANDLE) NULL);
                    111:           break;
                    112:         case IDM_DLLFUNCTION4:
                    113:           DLLFunction4 ((HWND) NULL);
                    114:           break;
                    115:         case IDM_DLLDIALOGBOX:
                    116:           DLLDialogBox (hwnd);
                    117:           break;
                    118:         default:
                    119:           break;
                    120:       }
                    121:       break;
                    122:     case WM_DESTROY:
                    123:       PostQuitMessage(NULL);
                    124:       break;
                    125:     default:
                    126:       return (DefWindowProc(hwnd, message, wParam, lParam));
                    127:   }
                    128:   return (NULL);
                    129: }
                    130: 
                    131: 
                    132: 
                    133: /************************************************************************\
                    134: *
                    135: *  FUNCTION:    Thread
                    136: *
                    137: *  GLOBAL VARS: hwndMain - handle of main app window
                    138: *
                    139: \************************************************************************/
                    140: 
                    141: void ThreadProc ()
                    142: {
                    143:   MessageBox (hwndMain, "calling DLLFunction1", "ThreadProc()", MB_OK);
                    144:   DLLFunction1 ();
                    145: }

unix.superglobalmegacorp.com

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