home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / ENTRPRIS / CALLBACK / CALLBACK.TXT next >
Encoding:
Text File  |  1996-11-23  |  5.0 KB  |  82 lines

  1. 'This sample demostrates the use of an ole object ptr being passed to
  2. 'an external (and optionally remote) ole server.  The ole server then
  3. 'periodically calls a method on this object ptr. This has the effect of
  4. 'a server initiated callback to the client... which can be a much better
  5. 'app model that the polling a client app might have to do otherwise to
  6. 'find the status of a server.  Although this demo simply returns the time
  7. 'to the client, it could just as easily return data, news, or other information
  8. 'it has been told the client wants to know.  The benefit here is that the
  9. 'server does all the work looking for data the client might need... and the
  10. 'client does other work... only being interrupted when the server actually 
  11. 'has something that interests it.
  12.  
  13. 'Note1: In this scenario, the client creates an object that is internal to it'
  14. 'It then creates an instance of the remote server and passes an object
  15. 'ptr to it of its internal object.  The server hangs onto the client's object,
  16. '"feeding it" from time to time.  At somepoint the client decides to
  17. 'disconnect (DropObjectReference) and the server does some clean up
  18. 'work in preparation for the client setting its reference to the server =
  19. 'Nothing.  Since this server has a visible form (servers usually will not
  20. 'have any visible displays except for debugging information), it unloads
  21. 'it at this point so that the instance will be closed by ole when the client
  22. 'sets the reference = Nothing.
  23.  
  24. 'Note2: Since the client created both the instance to its internal object
  25. 'and the instance to the server... it is important that the client be the one
  26. 'to close these instances by setting them = Nothing.  OLE errors will
  27. 'occur if the server tries to set the reference to the client = Nothing.
  28.  
  29. 'Note3: This app was developed very quickly... and should not be taken
  30. 'as gospel on how to build good servers.  For example, a good server
  31. 'should not have ANY msgbox calls outside of a debug mode.  (If a
  32. 'production server tried to display a msg for the user... it could wait a
  33. 'long time for someone to come by the server machine to click "OK".)
  34. 'This sample will be refined and cleaned up before final release.
  35.  
  36. 'Note4: The following class properties are critical for the behavior of
  37. 'the application:
  38. '
  39. '  "Instancing = Creatable SingleUse" This causes OLE to create a
  40. '           new physical instance of the class for each client.  This
  41. '           provides a simple programming model for creating parallel
  42. '           execution paths on the NT server, but requires a fair amount
  43. '           of memory to be allocated for each client.  Literally, SingleUse
  44. '           means the server is only used by a a single client at a time.
  45. '           A more efficient runtime model can be achieved if the setting
  46. '           of "Instancing = MultiUse" is set.  This causes OLE to only
  47. '           create an instance of the server for the first client... all other
  48. '           clients will get a ptr to the initial instance when they do their
  49. '           creates.  This model is more efficient from a memory standpoint,
  50. '           but OLE will only allow one client to use the class instance at
  51. '           a time... which could cause client blocking if the work the class
  52. '           does takes longer than the average client request interval.  A
  53. '           good compromise between these two implementation options is
  54. '           to use a pool of SingleUse servers.  In this case, 100 clients
  55. '           might have access to a pool of 10 class instances.  See the
  56. '           poolmngr sample for more details on this scenario.
  57. '
  58. '
  59. '  "Public = True" This allows external apps to access this class through
  60. '           OLE.
  61. '  "Name = Stuff" This name is used as the class name in the second part
  62. '           of the progid.  The client references this progid to tell OLE what
  63. '           object it wants to start.
  64.  
  65. 'Note5:
  66. 'In the Tools.Options.Project dialog, it is very important that the project name
  67. 'be set.  This is used by the client to define the project name in the progid.  After
  68. 'creating an ole server exe, the exe must be run once so that it can register its
  69. 'OLE typeinfo data in the system registry.  After running it once, close the server
  70. 'manually and everything should be set for your client app to call the server through
  71. 'OLE.
  72.  
  73. 'Note6: Every time you build a new exe of your server, VB will generate a new
  74. 'unique ID for each of its classes.  Since this ID must be the same ID that is also
  75. 'registered in the client machine's registry, this constant changing of the ID can
  76. 'make keeping the client and the server working together a real chore.  To get
  77. 'around this, go to the Tools.Options.Project dialog and set the "Compatible OLE
  78. 'Server" field to a previous instance of the server exe.  Then, each time VB rebuilds
  79. 'your server exe, it will steal the classid(s) out of the previous version.  It will also
  80. 'do other checking to try to make sure you have maintained compatibility with earlier
  81. 'versions.
  82.