OILModule Class Reference

This class hides the mechanism of loading modules via whatever OS calls are required. For example, under Windows it loads DLLs and interrogates them, whereas on the Arc something quite different could happen. It also provides a link between a kernel 'Module' item and the OIL transport mechanism used to load it. More...

#include <oilmods.h>

List of all members.

Public Member Functions

 OILModule ()
 Provides access to the OIL specific features of a module.
HINSTANCE GetInstance ()
 Returns the HINSTANCE of the DLL that this module's resources are in.

Static Public Member Functions

static BOOL Init ()
static void Deinit ()
static void DeinitExtras ()
static HINSTANCE GetInstance (UINT32 ModuleID)
 Given a module ID, return the Windows HINSTANCE handle for the Windows 'module' containing this Camelot module.

Private Attributes

HINSTANCE hInstance


Detailed Description

This class hides the mechanism of loading modules via whatever OS calls are required. For example, under Windows it loads DLLs and interrogates them, whereas on the Arc something quite different could happen. It also provides a link between a kernel 'Module' item and the OIL transport mechanism used to load it.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/6/93

Definition at line 115 of file oilmods.h.


Constructor & Destructor Documentation

OILModule::OILModule  ) 
 

Provides access to the OIL specific features of a module.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
GetInstance

Definition at line 502 of file oilmods.cpp.

00503 {
00504     // Initialise to a value that can be easily recognised as invalid.
00505     hInstance = (HINSTANCE)HINSTANCE_ERROR;
00506 }


Member Function Documentation

static void OILModule::Deinit  )  [static]
 

static void OILModule::DeinitExtras  )  [static]
 

HINSTANCE OILModule::GetInstance UINT32  ModuleID  )  [static]
 

Given a module ID, return the Windows HINSTANCE handle for the Windows 'module' containing this Camelot module.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/7/93
Parameters:
ModuleID - ID of the module to get the instance for. [INPUTS]
- [OUTPUTS]
Returns:
The HINSTANCE value for the required module, or HINSTANCE_ERROR if the ID was not found.

Errors: -

Definition at line 471 of file oilmods.cpp.

00472 {
00473     // Find the module in question
00474     ModuleListItem *Item = Module::Find(ModuleID);
00475     
00476     // Extract the instance if the module was found
00477     if (Item == NULL)
00478     {
00479         TRACE( _T("OILModule::GetInstance() : ModuleID (%d) not found\n"), ModuleID);
00480         return (HINSTANCE)HINSTANCE_ERROR;
00481     }
00482     else    
00483         return (Item->m_pOILModule->GetInstance());
00484 }

HINSTANCE OILModule::GetInstance  ) 
 

Returns the HINSTANCE of the DLL that this module's resources are in.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 524 of file oilmods.cpp.

00525 {
00526     return hInstance;
00527 }

BOOL OILModule::Init void   )  [static]
 

Kludged built in to .exe file Tool code:

Definition at line 173 of file oilmods.cpp.

00174 {
00175 // The Viewer, and Mac version always read from the exe
00176 #ifdef STANDALONE
00177 //  #define _READFROMEXE
00178 #endif
00179 
00180 #ifndef _READFROMEXE
00181     #ifdef _MAC
00182         #define _READFROMEXE
00183     #endif
00184 #endif
00185 
00186     HINSTANCE hLibrary = (HINSTANCE)HINSTANCE_ERROR;
00187 
00188 PORTNOTE("other", "Removed SetErrorMode usage" )
00189 #ifndef EXCLUDE_FROM_XARALX
00190     SetErrorMode( SEM_NOOPENFILEERRORBOX );                     // don't cause errors
00191 #endif
00192     
00193     // Still need the DLLs for the module/tool resources.
00194 
00195 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00196     // Have a look to see if the tools resources are in the normal ones...
00197     HINSTANCE hResInst = AfxGetResourceHandle();
00198     TCHAR Buf[200];
00199     INT32 LoadStringResult = ::LoadString( hResInst, _R(IDS_ZOOMOP_STATUSHELP), Buf, 200);
00200     if(LoadStringResult)
00201     {
00202         // if(ExtraDLLs[Resources_DLL] != 0)
00203         // We don't want to load the tools.dll if we're using an external resource
00204         // dll anyway, since it should already have these resources in it...
00205         hLibrary = (HINSTANCE)HINSTANCE_ERROR; //AfxGetInstanceHandle();
00206     }
00207     else
00208     {
00209 #ifndef _READFROMEXE
00210         LPTCHAR LibName = wxT(TOOL_DLL_NAME);
00211         hLibrary = LoadLibrary( LibName );
00212 
00213         // for now the tools DLL is compulsory
00214         if (hLibrary < (HINSTANCE)HINSTANCE_ERROR)
00215         {
00216     /*      TCHAR loaded[256], buf[256];
00217 
00218             if (::LoadString( AfxGetResourceHandle(), _R(IDW_NOTOOLS), loaded, sizeof(loaded) ) )
00219             {
00220                 wsprintf(buf, loaded, LibName );                // assumes %s in message
00221                 Error::SetError(0, buf, 0);                     // leave InformError for caller
00222             }
00223             return FALSE;       
00224     */
00225             // Rewrite the above to use MakeMsg, so the context-senstive help will work.
00226             String_256 buf;
00227             buf.MakeMsg(_R(IDW_NOTOOLS), (LPCTSTR) LibName);
00228             Error::SetError(0, buf, 0);                     // leave InformError to caller
00229             return FALSE;
00230         }
00231 #else
00232         // Mac version cannot open DLLs
00233         hLibrary = AfxGetInstanceHandle();                      // read resource from us
00234 #endif
00235     }
00236 //#else
00237 //  hLibrary = AfxGetInstanceHandle();                      // read resource from us
00238 #endif
00239 
00240     // Bodge the DLL table
00241     DLLs[0] = hLibrary;
00242     DLLCount++;
00243     
00244     Module *NewModule = (Module *) new ViewModule;
00245     if (NewModule == NULL)
00246         goto AbnormalExit;
00247     
00248     // Construct an OILModule and make it point to this DLL for the module's resources.
00249     OILModule *pOILModule;
00250     pOILModule = new OILModule;
00251     if (pOILModule == NULL)
00252     {
00253         delete NewModule;
00254         goto AbnormalExit;
00255     }
00256     pOILModule->hInstance = hLibrary;
00257     
00258     // Declare this module.
00259     Module::Declare(NewModule, pOILModule);
00260 
00261     // Here you add your own built-in tools for in .exe testing - when in a DLL,
00262     // you can't do this.
00263 
00264     return TRUE;
00265     
00266 AbnormalExit:
00267     // Out of memory - clean up and fail
00268     TRACEUSER( "Tim", _T("OILModule::Init(): memory exhausted") );
00269 PORTNOTE("other", "Removed FreeLibrary usage" )
00270 #ifndef EXCLUDE_FROM_XARALX
00271 //  FreeLibrary(hLibrary);
00272 #endif
00273     DLLs[0] = (HINSTANCE)HINSTANCE_ERROR;
00274     DLLCount--;
00275     return FALSE;
00276 }


Member Data Documentation

HINSTANCE OILModule::hInstance [private]
 

Definition at line 130 of file oilmods.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:57:21 2007 for Camelot by  doxygen 1.4.4