home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / mswindo / programm / misc / 3394 < prev    next >
Encoding:
Text File  |  1992-11-12  |  4.0 KB  |  148 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!think.com!ames!purdue!yuma!sailors
  3. From: sailors@CS.ColoState.EDU (robert sailors)
  4. Subject: ProgMan crashing on DDE
  5. Summary: ProgMan crashes when I try to add an icon and group.
  6. Sender: news@yuma.ACNS.ColoState.EDU (News Account)
  7. Message-ID: <Nov12.192036.56085@yuma.ACNS.ColoState.EDU>
  8. Date: Thu, 12 Nov 1992 19:20:36 GMT
  9. Nntp-Posting-Host: beethoven.cs.colostate.edu
  10. Organization: Colorado State University, Computer Science Department
  11. Lines: 135
  12.  
  13. I have a program that needs to just create a new group and an icon in that
  14. group of program manager and exit.  Running on my 486 and 386 systems, it
  15. runs fine.  As soon as I move over to a 1MB 286, the program crashes
  16. Program Manager saing 'PROGMAN caused a General Protection Fault in module
  17. PROGMAN.EXE at 0007:01A3.'
  18.  
  19. Basically, it just creates a window (so we have a location for ProgMan
  20. to send the ACKs to (though I'm not doing much with the ACK right now),
  21. and sends the DDE calls to ProgMan.
  22.  
  23. I'm including the entire text of the C program below (due to lack of length).
  24. The DDE happens in the WM_CREATE message, so you can search for that to find
  25. the curious bits.  If anyone has any suggestions on how this could be done
  26. better, I'd love to hear them.
  27.  
  28. Thanks,
  29. Sean
  30. ---------------------------------------8<-------------------------------------
  31. #include <windows.h>
  32. #include <string.h>
  33. #include <dde.h>
  34.  
  35. long FAR PASCAL WindowProc(HWND, unsigned, WORD, LONG);
  36. int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
  37.  
  38. static char *ProgramName = "Install Icons";
  39. static char *ClassName = "AddIcon";                /*  name for window class  */
  40. static char S_Command[150];
  41.  
  42.  
  43. /****************************/
  44. /*  main program procedure  */
  45.  
  46. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  47. HANDLE hInstance, hPrevInstance;
  48. LPSTR lpszCmdLine;
  49. int nCmdShow;
  50. {
  51. HWND WndHandle;
  52. WNDCLASS Class;
  53. MSG Message;
  54.  
  55.  
  56. /*  only allow one instance to run  */
  57. if (hPrevInstance)
  58.     return(FALSE);
  59.  
  60. Class.style         = CS_HREDRAW | CS_VREDRAW;
  61. Class.lpfnWndProc   = WindowProc;
  62. Class.cbClsExtra    = 0;
  63. Class.cbWndExtra    = 0;
  64. Class.hInstance     = hInstance;
  65. Class.hIcon         = LoadIcon(hInstance, "picon");
  66. Class.hCursor       = LoadCursor(NULL, IDC_ARROW);
  67. Class.hbrBackground = GetStockObject(WHITE_BRUSH);
  68. Class.lpszMenuName  = NULL;
  69. Class.lpszClassName = ClassName;
  70.  
  71. if (!RegisterClass(&Class))
  72.     return(FALSE);
  73.  
  74. /*  create comand to run  */
  75. strcpy(S_Command, "[CreateGroup(Medical Information Systems)]"
  76.         "[ShowGroup(Medical Information Systems,1)][AddItem(");
  77. lstrcat(S_Command, lpszCmdLine);
  78. strcat(S_Command, ",MIMS)]");
  79.  
  80. /*  open the window  */
  81. if (!(WndHandle = CreateWindow(ClassName, ProgramName,
  82.         WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL,
  83.         hInstance, NULL))) {
  84.     MessageBox(NULL, "Error creating window", ProgramName,
  85.             MB_OK | MB_ICONEXCLAMATION);
  86.     return(FALSE);
  87.     }
  88. ShowWindow(WndHandle, SW_HIDE);
  89. UpdateWindow(WndHandle);
  90.  
  91. /*  get messages until it's time to go  */
  92. while (GetMessage(&Message, NULL, 0, 0)) {
  93.     TranslateMessage(&Message);
  94.     DispatchMessage(&Message);
  95.     }
  96.  
  97. return(Message.wParam);
  98. }
  99.  
  100.  
  101. long FAR PASCAL WindowProc(hWnd, iMessage, wParam, lParam)
  102. HWND hWnd;
  103. unsigned iMessage;
  104. WORD wParam;
  105. LONG lParam;
  106. {
  107. static HWND S_ProgMan = NULL;
  108.  
  109.  
  110. switch(iMessage) {
  111.     case WM_CREATE: {
  112.         ATOM App = GlobalAddAtom((LPSTR) "PROGMAN");
  113.         HANDLE Cmd = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, 100);
  114.         LPSTR pCmd;
  115.  
  116.  
  117.         if (!App || !Cmd)
  118.             ;
  119.         pCmd = GlobalLock(Cmd);
  120.         lstrcpy(pCmd, S_Command);
  121.         GlobalUnlock(Cmd);
  122.  
  123.         SendMessage(-1, WM_DDE_INITIATE, hWnd, MAKELPARAM(App, App));
  124.         SendMessage(S_ProgMan, WM_DDE_EXECUTE, hWnd, MAKELPARAM(0, Cmd));
  125.         PostMessage(S_ProgMan, WM_DDE_TERMINATE, hWnd, 0L);
  126.         GlobalDeleteAtom(App);
  127.         GlobalFree(Cmd);
  128.  
  129.         /*  close the window  */
  130.         SendMessage(hWnd, WM_DESTROY, 0, 0L);
  131.         }
  132.         break;
  133.  
  134.     case WM_DDE_ACK:
  135.         S_ProgMan = wParam;
  136.         break;
  137.     
  138.     case WM_DESTROY:
  139.         PostQuitMessage(0);
  140.         break;
  141.  
  142.     default:
  143.         return(DefWindowProc(hWnd, iMessage, wParam, lParam));
  144.     }
  145.  
  146. return(FALSE);
  147. }
  148.