home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / SOURCE.ZIP / ARGCARGV.C next >
Encoding:
C/C++ Source or Header  |  1992-06-08  |  2.9 KB  |  122 lines

  1. /*
  2. ARGCARGV.C -- WinMain->main startup for WINIO library
  3. Changed considerably since the version in MSJ (May 1991)
  4.  
  5. from "Undocumented Windows"  (Addison-Wesley, 1992)
  6. by Andrew Schulman, Dave Maxey and Matt Pietrek.
  7.  
  8. Copyright (c) Dave Maxey and Andrew Schulman 1991-1992
  9.  
  10. MSC/C++ 7.0 has QuickWin library.  It's not adequate for our
  11. purposes, but its main() gets in the way of ours.  Need to
  12. link with ARGCARGV.OBJ; can't put ARGCARGV.OBJ in a library
  13. */
  14.  
  15. #include "windows.h"
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "winio.h"
  19.  
  20. #define MAIN_BUFFER 32760
  21.  
  22. #ifdef __BORLANDC__
  23. // Borland must have followed (incorrect) doc in SDK Guide, p. 14-3
  24. #define argc _argc
  25. #define argv _argv
  26. // #define argc _C0argc
  27. // #define argv _C0argv
  28.  
  29. extern int _argc;
  30. extern char **_argv;
  31. // extern int _C0argc;
  32. // extern char **_C0argv;
  33. #else
  34. // Microsoft C code per MSJ, May 1991, pp. 135-6
  35. #define argc __argc
  36. #define argv __argv
  37.  
  38. extern int __argc;
  39. extern char **__argv;
  40. #endif
  41.  
  42. // weird! couldn't find environ
  43. // oh well, nobody ever uses it!
  44. #if defined(_MSC_VER) && (_MSC_VER >= 700)
  45. extern int main(int argc, char **argv);
  46. #else
  47. extern int main(int argc, char **argv, char **envp);
  48. #endif
  49.  
  50. void getexefilename(HANDLE hInst, char *strName);
  51.  
  52. HANDLE __hInst;
  53. HANDLE __hPrevInst;
  54. LPSTR __lpCmdLine;
  55. int __nCmdShow;
  56. HWND __hMainWnd;
  57. WORD __hAppTimer;
  58. char __szModule[9] = {0};
  59.  
  60. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, 
  61.     LPSTR lpCmdLine, int nCmdShow)
  62.     {
  63.     int ret;
  64.     
  65.     __hInst = hInstance;
  66.     __hPrevInst = hPrevInstance;
  67.     __lpCmdLine = lpCmdLine;
  68.     __nCmdShow = nCmdShow;
  69.     
  70.     getexefilename(__hInst, __szModule);
  71.     winio_about(__szModule);    // default; can override
  72.     
  73.     if (! winio_init())
  74.         {
  75.         winio_warn(FALSE, __szModule, "Could not initialize");
  76.         return 1;
  77.         }
  78.     
  79.     if (__hMainWnd = winio_window((LPSTR) NULL, MAIN_BUFFER,
  80.                 WW_HASMENU | WW_EXITALLOWED))
  81.         {
  82.         // App timer to allow multitasking
  83.         __hAppTimer = SetTimer(NULL, 0xABCD, 100, NULL);
  84.     
  85.         winio_setcurrent(__hMainWnd);
  86.         
  87. #if defined(_MSC_VER) && (_MSC_VER >= 700)
  88.         ret = main(argc, argv);
  89. #else   
  90.         ret = main(argc, argv, environ);
  91. #endif  
  92.  
  93.         winio_end();
  94.     
  95.         if (__hAppTimer)
  96.             KillTimer(NULL, __hAppTimer);
  97.         }
  98.     else
  99.         {
  100.         winio_warn(FALSE, __szModule, "Could not create main window");
  101.         ret = -1;
  102.         }
  103.     
  104.     return ret;
  105.     }
  106.  
  107.  
  108. void getexefilename(HANDLE hInst, char *strName)
  109.     {
  110.     char str[128];
  111.     char *p;
  112.  
  113.     // can use hInst as well as hMod (GetExePtr does the trick)
  114.     GetModuleFileName(hInst, str, 128);
  115.     p = &str[strlen(str) - 1];
  116.     
  117.     for ( ; (p != str) && (*p != '\\'); p--)
  118.         if (*p == '.') *p = 0;
  119.         
  120.     strcpy(strName, *p == '\\' ? ++p : p);
  121.     }
  122.