home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wpsgpf.zip / TRYSIM.C < prev    next >
Text File  |  1995-02-22  |  3KB  |  90 lines

  1. #define INCL_DOSERRORS
  2. #define INCL_WINERRORS
  3. #define INCL_WINWINDOWMGR
  4. #define INCL_WINWORKPLACE
  5. #include <os2.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8.  
  9. #define LOCATION   "<WP_DESKTOP>"
  10. #define CLASSNAME  "WPSimple"
  11. #define OBJECTNAME "My"
  12. #define DLLNAME    "sim"
  13. /* #define SETUP      NULL*/
  14. #define SETUP      "ICONNUMBER=3"
  15.  
  16. /*===========================================================================*/
  17. VOID Use (VOID) {
  18.    printf ("use:   tryit [/d | /r | /c]\n");
  19.    printf ("where: /d is deregister only\n");
  20.    printf ("       /r is register   only\n");
  21.    printf ("       /c is create     only\n");
  22.    exit (-1);
  23. }
  24.  
  25. #define TODO_DEREGISTER 0x0001
  26. #define TODO_REGISTER   0x0002
  27. #define TODO_CREATE     0x0004
  28.  
  29. /*===========================================================================*/
  30. int main(int argc, char **argv)
  31. {
  32.     HAB     hab;
  33.     BOOL    fToDo = 0x0000;
  34.     ERRORID errid;
  35.  
  36.     hab = WinQueryAnchorBlock (HWND_DESKTOP);
  37.  
  38.     if (1 == argc) {
  39.        fToDo = TODO_DEREGISTER | TODO_REGISTER | TODO_CREATE;
  40.     } else if (2 == argc) {
  41.        if (strcmp (argv [1], "/d") == 0) {
  42.           fToDo |= TODO_DEREGISTER;
  43.        } else if (strcmp (argv [1], "/r") == 0) {
  44.           fToDo |= TODO_REGISTER;
  45.        } else if (strcmp (argv [1], "/c") == 0) {
  46.           fToDo |= TODO_CREATE;
  47.        } else if (strcmp (argv [1], "/?") == 0) {
  48.           Use ();
  49.        } else {
  50.           Use ();
  51.        }
  52.     } else  {
  53.        Use ();
  54.     }
  55.     /*-----------------------------------------------------------------------*/
  56.     if (fToDo & TODO_DEREGISTER) {
  57.        if (WinDeregisterObjectClass(CLASSNAME)) {
  58.           printf("Deregister %s OK\n", CLASSNAME);
  59.        } else {
  60.           printf("Failed to deregister %s (Err: %lx)\n",
  61.                  CLASSNAME, WinGetLastError (hab));
  62.        }
  63.     }
  64.  
  65.     /*-----------------------------------------------------------------------*/
  66.     if (fToDo & TODO_REGISTER) {
  67.        if (WinRegisterObjectClass(CLASSNAME, DLLNAME)) {
  68.           printf("Register %s (%s) OK\n", CLASSNAME, DLLNAME);
  69.        } else {
  70.           printf("Failed to register %s (%s) (Err: %lx)\n",
  71.                  CLASSNAME, DLLNAME, WinGetLastError (hab));
  72.        }
  73.     }
  74.  
  75.     /*-----------------------------------------------------------------------*/
  76.     if (fToDo & TODO_CREATE) {
  77.        if (WinCreateObject(CLASSNAME, OBJECTNAME, SETUP, LOCATION,
  78.            CO_REPLACEIFEXISTS )) {
  79.           printf("Object %s of class %s created in %s\n",
  80.                  OBJECTNAME, CLASSNAME, LOCATION);
  81.        } else {
  82.           printf("Failed to create %s of class %s (Err: %lx)\n",
  83.                  OBJECTNAME, CLASSNAME, WinGetLastError (hab));
  84.        }
  85.     }
  86.  
  87.     return 0;
  88. }
  89.  
  90.