home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / mswindo / programm / misc / 1541 < prev    next >
Encoding:
Text File  |  1992-08-27  |  5.2 KB  |  184 lines

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!pdxgate!rigel!jayward
  2. From: jayward@rigel.cs.pdx.edu (Jay Ward)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: WndProc comes a crashing down! (Borland C)
  5. Summary: Please Help
  6. Keywords: windows borland c++ help!!
  7. Message-ID: <6036@pdxgate.UUCP>
  8. Date: 28 Aug 92 00:26:01 GMT
  9. Article-I.D.: pdxgate.6036
  10. Sender: news@pdxgate.UUCP
  11. Lines: 171
  12.  
  13. I am a new-to-Windows programmer and I seem to be living in interesting
  14. times!  No matter what I try my WndProc crashes after processing
  15. the WM_CREATE message.  My WM_CREATE section calls another function
  16. and all seems to go well (according to Turbo Debugger/W), but when
  17. the WndProc tries to return I get an 'Exception 13' (from TD/W) and
  18. an Application Error (when run from within the BCW IDE).  I've tried
  19. compiling with both the small and medium models with no success.
  20.  
  21. Please help me before I go bald from rooting my hair!!!
  22.  
  23. Source follows (use default BCW .DEF file):
  24.  
  25. -------------8<---------------cut here -------->8--------------------
  26.  
  27.  
  28. /*--------------------------------------------
  29.     CPB2.H
  30. --------------------------------------------*/
  31.  
  32. #define    ALERT(str)    MessageBox(hwnd, str, "DEBUG", MB_ICONEXCLAMATION|MB_OK)
  33.  
  34. /*--------------------------------------------
  35.     END -- CPB2.H
  36. --------------------------------------------*/
  37.  
  38.  
  39. /*-----------------------------------------------------
  40.      CPB2.C
  41. -----------------------------------------------------*/
  42.  
  43. #include <stdio.h>
  44. #include <windows.h>
  45. #include <string.h>
  46. #include <dir.h>
  47. #include "cpb2.h"
  48.  
  49. extern    char    *envpath, *oldpath;
  50. void FAR PASCAL init(HWND);
  51. void cleanup(HWND);
  52. long FAR PASCAL WndProc(HWND, WORD, WORD, LONG);
  53.  
  54. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  55.                     LPSTR lpszCmdLine, int nCmdShow)
  56.      {
  57.      static char    szAppName[] = "CPB2";
  58.      HWND           hwnd;
  59.      MSG            msg;
  60.      WNDCLASS       wndclass;
  61.  
  62.      if (!hPrevInstance)
  63.           {
  64.           wndclass.style           = CS_HREDRAW | CS_VREDRAW;
  65.           wndclass.lpfnWndProc     = WndProc;
  66.           wndclass.cbClsExtra      = 0;
  67.           wndclass.cbWndExtra      = 0;
  68.           wndclass.hInstance       = hInstance;
  69.           wndclass.hIcon           = LoadIcon (NULL, IDI_APPLICATION);
  70.           wndclass.hCursor         = LoadCursor (NULL, IDC_ARROW);
  71.           wndclass.hbrBackground   = GetStockObject(WHITE_BRUSH);
  72.           wndclass.lpszMenuName    = NULL;
  73.           wndclass.lpszClassName   = szAppName;
  74.      
  75.           RegisterClass (&wndclass) ;
  76.           }
  77.      
  78.      hwnd = CreateWindow (szAppName, "CPBackup .DIR info",
  79.                          WS_OVERLAPPEDWINDOW,
  80.                          CW_USEDEFAULT, CW_USEDEFAULT,
  81.                          CW_USEDEFAULT, CW_USEDEFAULT,
  82.                          NULL, NULL, hInstance, NULL);
  83.      
  84.      ShowWindow (hwnd, nCmdShow);
  85.      UpdateWindow (hwnd);
  86.      
  87.      while (GetMessage (&msg, NULL, 0, 0))
  88.           {
  89.           TranslateMessage (&msg);
  90.           DispatchMessage (&msg);
  91.           }
  92.      return msg.wParam;
  93.      }
  94.  
  95. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  96. {
  97.     char            szBuffer[10], szCurr_dir[MAXDRIVE], szPct_dir[MAXDRIVE];
  98.     HDC                hdc;
  99.     PAINTSTRUCT        ps;
  100.  
  101.     switch (message)
  102.         {
  103.         case WM_CREATE :
  104. //            hdc = GetDC(hwnd);
  105.             init(hwnd);
  106.             ALERT("Done with init()");
  107.             sprintf(szCurr_dir, "The current directory is: %s", oldpath);
  108.             sprintf(szPct_dir, "The PCTOOLS directory is: %s", envpath);
  109. //            ReleaseDC (hwnd, hdc);
  110.             ALERT("We outta here");
  111.             return 0;
  112.  
  113.         case WM_PAINT :
  114.             hdc = BeginPaint (hwnd, &ps);
  115.             TextOut(hdc, 1,1, szCurr_dir, strlen(szCurr_dir));
  116.             TextOut(hdc, 1,10 ,szPct_dir, strlen(szPct_dir));
  117.             EndPaint(hwnd, &ps);
  118.             return 0;
  119.  
  120.         case WM_DESTROY :
  121.             PostQuitMessage(0);
  122.             cleanup(hwnd);
  123.             return 0;
  124.         }
  125.  
  126.     return DefWindowProc (hwnd, message, wParam, lParam);
  127. }
  128.  
  129. /*-------------------------------------------------
  130.     END CPB2.C
  131. -------------------------------------------------*/
  132.  
  133. /*-----------------------------------------
  134.     INIT.C
  135. -----------------------------------------*/
  136.  
  137. #include <windows.h>
  138. #include <stdio.h>
  139. #include <stdlib.h>
  140. #include <dir.h>
  141. #include <direct.h>
  142. #include "cpb2.h"
  143.  
  144. char    *envpath, envdrive[MAXDRIVE], *oldpath, olddrive[MAXDRIVE];
  145.  
  146. void FAR PASCAL init(HWND hwnd)
  147. {
  148.     // Remember, oldpath needs to be free()'d
  149.     if((oldpath=getcwd(NULL, MAXPATH))==NULL){
  150.         MessageBox(hwnd, "getcwd()", "ERROR!", MB_ICONSTOP|MB_OK);
  151.         exit(-1);
  152.     }
  153.     fnsplit(oldpath, olddrive, NULL, NULL, NULL);
  154.  
  155.     envpath=getenv("PCTOOLS");
  156.     fnsplit(envpath, envdrive, NULL, NULL, NULL);
  157.     chdir(envpath);
  158.     if(_chdrive(*envdrive-'A'+1)) {
  159.         MessageBox(hwnd, "_chdrive()", "Error in function init():", MB_ICONHAND|MB_OK);
  160.         exit(-1);
  161.     }
  162. }
  163.  
  164. void cleanup(HWND hwnd)
  165. {
  166.     chdir(oldpath);
  167.     free(oldpath);
  168.     if(_chdrive(*olddrive-'A'+1)) {
  169.         MessageBox(hwnd, "_chdrive()", "Error in function init():", MB_ICONHAND|MB_OK);
  170.         exit(-1);
  171.     }
  172.  
  173. }
  174.  
  175. /*--------------------------------------------
  176.     END -- INIT.C
  177. --------------------------------------------*/
  178.  
  179.  
  180.           ||  Jay Ward || jayward@rigel.cs.pdx.edu  || 
  181.           ||=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-||
  182.           ||        Portland State University       ||
  183.           ||            Portland, Oregon            ||
  184.