home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / findhe.txt < prev    next >
Text File  |  1994-06-25  |  7KB  |  201 lines

  1. This is how I write my WPS objects:
  2.  
  3. 1. I find an object already written.  You can use the  car sample.
  4.  
  5. 2. Think of a name for your class.  If it is going to just do stuff for you
  6. you could call it Worker or WorkerClass or whatever you want.  You should
  7. probably use your app name somewhere in there.  Also come up with a file
  8. name and is <= 8 chars like worker.
  9.  
  10. 3. Copy car files to new directory off toolkt21\c\samples\ Rename all Car
  11. file names to Worker.
  12.  
  13. 4. edit worker.csc.  This is the SOM definition file.  Look at the toolkit pub
  14. for info on the parts of the SOM definition file.  change all references to
  15. Car to your class.  change the external prefix, etc.  Also change the parent
  16. class.  Your object should probably inherit from WPAbstract.  (wpabs.sc)
  17. To start simple, take out passthru statements, take out instance data (you
  18. can add some later if you need it), take out new methods (release order and
  19. method defines that don't say override).
  20.  
  21. 5. Add or remove methods you want to override.  Methods that start with wp
  22. are instance methods and those starting with wpcls are class methods.
  23. Look at the docs or the comments in car.c for info on what the methods do.
  24. You'll get better results if you just ask here.  There isn't any good docs
  25. on it yet (I'm working on it).
  26.  
  27. 6. You should override wpSetup for IPC with your other program (assuming
  28. you're still going to have another program).  You can make up your own key
  29. name like APPWINDOW= and give the window handle and then use messages and/or
  30. DDE to communicate back and forth.  The object can create an invisible
  31. window to handle the object's communication end.
  32.  
  33. 7. edit makefile and change stuff.  Delete the .def file and SOM will create
  34. one as long as .def is included in the things to build in the sc command.
  35. (check SMEMIT and put in .def) or just edit worker.def and change Car to the
  36. class name and change the library name.
  37.  
  38. 8. rename the .C file to something else because it is full of Car class
  39. stuff and you want SOM to generate a new one that will have stuff for your
  40. class.  compile.  When icc starts, hit ctrl+c because SOM generated the .C
  41. file but you have to edit it to add the code you need.
  42.  
  43. 9.  Add code to the .C file.  When you need a new method, or method override
  44. or instance data, add it to the .csc file and recompile.  SOM will add the
  45. method call to the bottom of your .C file.  BEWARE: SOM will #define
  46. SOM_CurrentClass to be either your class or your metaclass at different
  47. sections of the .C file for the instance methods and the class methods.
  48.  
  49. When you recompile and SOM adds new methods to the bottom, if they are
  50. instance methods they will be out of place and you will have to move them to
  51. the area in the code where the other instance methods are.  (otherwise you
  52. will pull your hair out very often)
  53.  
  54. 10. replace SOMOutCharRoutine with your own (see SOM prog guide in toolkit)
  55. so you can use SOMMethodDebug.  somMethodDebug will call somPrintf which
  56. calls SOMOutCharRoutine for every character outputted.  By default it will
  57. goto stdout (very useful in PM...NOT!).  have it output to a file so you can
  58. see the flow of the code.  I've never done this so maybe someone else can
  59. help you out with it.  Make sure you don't ship your product with the
  60. SOMOutCharRoutine replaced because only one can exist for each process and
  61. you are sharing the process with other WPS apps.  (not very friendly to
  62. hinder someone else's debugging)
  63.  
  64. 11.  Let's see what else???  Be patient and ask as many questions you want
  65. on the developer forum.
  66.  
  67. 12.  put the .DLL in the LIBPATH, register the class with workplace,
  68. and create an object.  REXX code snippet:
  69.  
  70. /* Register a Workplace class  */
  71.  
  72. /* Load the REXX utility functions  */
  73. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  74. call SysLoadFuncs
  75.  
  76. /* Register new class with Shell */
  77.  
  78. result = SysRegisterObjectClass("MyClass", "MYCLASS")
  79. if result
  80.      then say 'Class registration successfully completed'
  81.      else say 'SysRegisterObjectClass failed.  RC =' result
  82.  
  83. rc = SysCreateObject('MyClass', 'Test', '<WP_DESKTOP>','OBJECTID=<TEST>',,
  84.       'ReplaceIfExists');
  85.  
  86. if rc = 1 then
  87.    say 'object created successfully'
  88. else
  89.    say 'object not created successfully'
  90.  
  91. -----------------------------------------------------------------------------
  92.  
  93. Here's some code for find:
  94.  
  95. This function is a thread (thus the message queue)  It finds all the printer
  96. objects off the desktop tree and, if found, sets the local printer to the
  97. default.  Not useful but gets the point across.
  98.  
  99. VOID FindPrinterObjects(VOID)
  100. {
  101.    CLASS   apClass[2];
  102.    HFIND   hFind;
  103.    SOMAny  *Desktop, **pBuffer;
  104.    BOOL    bReturn;
  105.    ULONG   ulError = 0, ulCount = 10;
  106.    HMQ    hmq = 0;
  107.    HAB    hab = 0;
  108.  
  109.    hab = WinInitialize(0);
  110.    if (!hab)
  111.       return;
  112.  
  113.    /* workplace threads need message queues */
  114.    hmq = WinCreateMsgQueue(hab, 0);
  115.    if (hmq)
  116.       WinCancelShutdown(hmq, TRUE);
  117.    else
  118.    {
  119.       WinTerminate(hab);
  120.       return;
  121.    }
  122.  
  123.   /* array of classes.  only one at a time works */
  124.    apClass[0] = _WPPrinter;
  125.    apClass[1] = NULL;
  126.  
  127.    /* get desktop object */
  128.    Desktop = _wpclsQueryFolder(_WPObject, "<WP_DESKTOP>", FALSE);
  129.    if (Desktop)
  130.    {
  131.       /* alloc buffer */
  132.       pBuffer = malloc(sizeof(SOMAny *) * ulCount);
  133.       if (pBuffer)
  134.       {
  135.          _wpclsSetError(_WPObject, 0);
  136.  
  137.          /* start the find */
  138.          bReturn = _wpclsFindObjectFirst(_WPObject, apClass, &hFind, "*",
  139.                                        Desktop, TRUE, NULL, pBuffer, &ulCount);
  140.          if (!bReturn)
  141.             ulError = _wpclsQueryError(_WPObject);
  142.  
  143.          if (!ulError || ulError == WPERR_BUFFER_OVERFLOW)
  144.          {
  145.             ProcessBuffer(pBuffer, ulCount);
  146.  
  147.             /* loop for more: bug-> ulError could be overflow when ulCount
  148.              * is zero.  (should be WPERR_OBJECT_NOT_FOUND)
  149.              */
  150.             while (ulCount && ulError == WPERR_BUFFER_OVERFLOW)
  151.             {
  152.                ulError = 0;
  153.                ulCount = 10;
  154.  
  155.                _wpclsSetError(_WPObject, 0);
  156.                bReturn = _wpclsFindObjectNext(_WPObject, hFind, pBuffer,
  157.                                               &ulCount);
  158.  
  159.                if (!bReturn)
  160.                   ulError = _wpclsQueryError(_WPObject);
  161.  
  162.                if (!ulError || ulError == WPERR_BUFFER_OVERFLOW)
  163.                {
  164.                   ProcessBuffer(pBuffer, ulCount);
  165.                }
  166.             }
  167.             /* all done.  close find */
  168.             _wpclsFindObjectEnd(_WPObject, hFind);
  169.          }
  170.          free(pBuffer);
  171.       }
  172.    }
  173.  
  174.    WinDestroyMsgQueue(hmq);
  175.  
  176.    WinTerminate(hab);
  177. }
  178.  
  179.  
  180. VOID ProcessBuffer(SOMAny **pBuffer, ULONG ulCount)
  181. {
  182.    ULONG i;
  183.    CHAR  szMessage[256];
  184.    PSZ   pszTitle;
  185.    FILE  *fpFile;
  186.  
  187.    for (i = 0; i < ulCount; i++)
  188.    {
  189.       if (_wpQueryComputerName(pBuffer[i], szMessage) == 1 )
  190.       {
  191.          _wpSetDefaultPrinter(pBuffer[i]);
  192.       }
  193.       /* you must unlock each object because workplace locks them
  194.        * when doing a find.
  195.        */
  196.       _wpUnlockObject(pBuffer[i]);
  197.    }
  198. }
  199.  
  200. If you have any questions, send a note to Mindy Pollack id: 74047.2731
  201.