/* dllcall.c   example of calling a function in a dll */

#include <windows.h>
#include "dllcall.h"    /* header file for this program */
#include "revstr.h"     /* header file for dll */

int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine,
         int nCmdShow)
{
         HWND        hWnd ;      /* the window's "handle" */
         MSG         msg ;       /* a message structure */
         WNDCLASS    wndclass ;  /* window class structure */
         char        cBuf [128] ;

                  wndclass.style          = CS_HREDRAW | CS_VREDRAW ;
                  wndclass.lpfnWndProc    = WndProc ;
                  wndclass.cbClsExtra     = 0 ;
                  wndclass.cbWndExtra     = 0 ;
                  wndclass.hInstance      = hInstance ;
                  wndclass.hIcon          = NULL ;
                  wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW) ;
                  wndclass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH) ;
                  wndclass.lpszMenuName   = "MyMenu" ;
                  wndclass.lpszClassName  = "MyClass" ;
                                                /* register the window class */
                  if (!RegisterClass (&wndclass))
                                return 0 ;

         LoadString (hInstance, S_PROGRAMCAPTION, cBuf, sizeof (cBuf)) ;

         hWnd = CreateWindow ("MyClass", cBuf, WS_OVERLAPPEDWINDOW,
                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                  NULL, NULL, hInstance, NULL) ;

         ShowWindow (hWnd, nCmdShow) ;   /* display the window */
         UpdateWindow (hWnd) ;

         while (GetMessage (&msg, NULL, 0, 0))   /* message loop */
         {
                  TranslateMessage (&msg) ;   /* translate keyboard messages */
                  DispatchMessage (&msg) ;    /* send message to WndProc() */
         }
         return (msg.wParam) ;
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT wMessage, 
                                    WPARAM wParam, LPARAM lParam)
{
    HINSTANCE   hInstance ;
    HANDLE  hgMem ;
    LPSTR   lpStr ;
    HDC     hDC ;
    int     nStringLong ;
    
    switch (wMessage)       /* process windows messages */
    {
        case WM_COMMAND:
            switch (wParam)
            {
                case IDM_SHOW:
                    hDC = GetDC (hWnd) ;
                    hInstance =(HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE);
                    hgMem = (HANDLE)GlobalAlloc (GHND, 128) ;
                    if (hgMem)
                    {
                        lpStr = (LPSTR)GlobalLock (hgMem) ;
                        LoadString (hInstance, S_EXAMPLESTRING, lpStr, 128);
                        nStringLong = lstrlen (lpStr) ;
                        TextOut (hDC, 0, 0, lpStr, nStringLong) ;
                        GlobalUnlock (hgMem) ;
                        BlockRev (hgMem, nStringLong) ;
                        lpStr = (LPSTR)GlobalLock (hgMem) ;
                        TextOut (hDC, 0, 30, lpStr, nStringLong) ;
                        GlobalUnlock (hgMem) ;
                    }
                    ReleaseDC (hWnd, hDC) ;
                    break ;
                case IDM_QUIT:              /* Quit menu item */
                    DestroyWindow (hWnd) ;  /* destroy window, */
                    break ;     /* terminating application */
            }
            break ;
        case WM_DESTROY:    /* stop application */
            PostQuitMessage (0) ;
            break ;
        default:        /* default windows message processing */
            return (DefWindowProc (hWnd, wMessage, wParam, lParam)) ;
    }
    return (0) ;
}