home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / hpp.z / WMODULE.HPP < prev    next >
C/C++ Source or Header  |  1996-10-18  |  3KB  |  119 lines

  1. /**********************************************************************
  2.  * 
  3.  * WModule
  4.  *
  5.  *     A wrapper class for handling modules (EXE and DLL handles).
  6.  *     Unlike other classes, no reference counting is done.  You
  7.  *     must explicitly load and unload DLLs.  This is done so that
  8.  *     you don't accidentally unload a DLL when you don't want to.
  9.  *
  10.  *********************************************************************/
  11.  
  12. #ifndef _WMODULE_HPP_INCLUDED
  13. #define _WMODULE_HPP_INCLUDED
  14.  
  15. #ifndef _WNO_PRAGMA_PUSH
  16. #pragma pack(push,8);
  17. #pragma enum int;
  18. #endif
  19.  
  20. #ifndef _WOBJECT_HPP_INCLUDED
  21. #  include "wobject.hpp"
  22. #endif
  23. #ifndef _WSTRING_HPP_INCLUDED
  24. #  include "wstring.hpp"
  25. #endif
  26.  
  27. class WBuffer;
  28.  
  29. class WCMCLASS WModule : public WObject {
  30.     WDeclareSubclass( WModule, WObject )
  31.  
  32.     public:
  33.  
  34.         /****************************************************************
  35.          * Constructors/destructors
  36.          ****************************************************************/
  37.  
  38.         // See the Load methods below...
  39.  
  40.         WModule();
  41.         WModule( const WModuleHandle handle );
  42.         WModule( const WModule & copy );
  43.  
  44.         ~WModule();
  45.  
  46.         /****************************************************************
  47.          * Properties
  48.          ****************************************************************/
  49.  
  50.         // Name 
  51.         //
  52.         //    Returns the full path of the module. 
  53.  
  54.         WString GetName() const;
  55.  
  56.         // Handle
  57.         //
  58.         //    The system handle for the module.
  59.  
  60.         WModuleHandle GetHandle() const { return _module; }
  61.  
  62.         /****************************************************************
  63.          * Methods
  64.          ****************************************************************/
  65.  
  66.         // FindProcedure
  67.         //
  68.         //    Return the address of an exported procedure.
  69.  
  70.         void *FindProcedure( const WChar *name ) const;
  71.  
  72.         // Load
  73.         //
  74.         //    Load a DLL by the given name, or attach to an already
  75.         //    loaded DLL.
  76.  
  77.         WBool Load( const WChar *path=NULL,
  78.                     WBool loadLibraryAsDataOnly=FALSE );
  79.         WBool Load( const WModuleHandle handle );
  80.         WBool Load( const WModule & copy );
  81.  
  82.         // LoadResourceData
  83.         //
  84.         //    Load the data for a resource and store it in the
  85.         //    give WBuffer.  Returns TRUE if the resource was
  86.         //    found and loaded.
  87.  
  88.         WBool LoadResourceData( const WResourceID & id, WBuffer *buf ) const;
  89.  
  90.         // Unload
  91.         //
  92.         //    Unload the DLL.
  93.  
  94.         WBool Unload();
  95.  
  96.         /****************************************************************
  97.          * Operators
  98.          ****************************************************************/
  99.  
  100.         WModule& operator=( const WModule & copy );
  101.         WModule& operator=( const WModuleHandle & handle );
  102.  
  103.         int operator==( const WModule & other );
  104.  
  105.         int operator!=( const WModule & other );
  106.  
  107.         operator WModuleHandle() const { return _module; }
  108.  
  109.     private:
  110.         WModuleHandle _module;
  111. };
  112.  
  113. #ifndef _WNO_PRAGMA_PUSH
  114. #pragma enum pop;
  115. #pragma pack(pop);
  116. #endif
  117.  
  118. #endif // _WMODULE_HPP_INCLUDED
  119.