home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / VBX / ARGCARGV.C next >
C/C++ Source or Header  |  1993-10-16  |  3KB  |  123 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. UINT __hAppTimer;
  58. char __szModule[9] = {0};
  59.  
  60. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE 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.     __hMainWnd = winio_window((LPSTR) NULL, MAIN_BUFFER,
  80.                 WW_HASMENU | WW_EXITALLOWED);
  81.     if (__hMainWnd)
  82.         {
  83.         // App timer to allow multitasking
  84.         __hAppTimer = SetTimer(NULL, 0xABCD, 100, NULL);
  85.     
  86.         winio_setcurrent(__hMainWnd);
  87.         
  88. #if defined(_MSC_VER) && (_MSC_VER >= 700)
  89.         ret = main(argc, argv);
  90. #else   
  91.         ret = main(argc, argv, environ);
  92. #endif  
  93.  
  94.         winio_end();
  95.     
  96.         if (__hAppTimer)
  97.             KillTimer(NULL, __hAppTimer);
  98.         }
  99.     else
  100.         {
  101.         winio_warn(FALSE, __szModule, "Could not create main window");
  102.         ret = -1;
  103.         }
  104.     
  105.     return ret;
  106.     }
  107.  
  108.  
  109. void getexefilename(HANDLE hInst, char *strName)
  110.     {
  111.     char str[128];
  112.     char *p;
  113.  
  114.     // can use hInst as well as hMod (GetExePtr does the trick)
  115.     GetModuleFileName(hInst, str, 128);
  116.     p = &str[strlen(str) - 1];
  117.     
  118.     for ( ; (p != str) && (*p != '\\'); p--)
  119.         if (*p == '.') *p = 0;
  120.         
  121.     strcpy(strName, *p == '\\' ? ++p : p);
  122.     }
  123.