home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / edtrccln.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.3 KB  |  148 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /* edtrccln.h edtor client wrapper */
  20. /* Dynamic Library wrapper for loading on call*/
  21.  
  22. #include "stdafx.h"
  23. #include "edtrccln.h"
  24.  
  25. #ifdef WIN32
  26. #define EDITORDLL "EDITOR32.DLL"
  27. #else
  28. #define EDITORDLL "EDITOR16.DLL"
  29. #endif
  30.  
  31. HINSTANCE CEditorResourceDll::s_dllinstance=NULL;
  32. unsigned int CEditorResourceDll::s_refcount=0;
  33. IMAGEDIALOGCONSTRUCTOR CEditorResourceDll::s_pimagedialog=NULL;
  34. IJPEGDLGCONSTRUCTOR CEditorResourceDll::s_pjpegdialog=NULL;
  35. TAGDIALOGCONSTRUCTOR CEditorResourceDll::s_ptagdialog=NULL;
  36. IMEDLLCONSTRUCTOR CEditorResourceDll::s_pimedll=NULL;
  37.  
  38. #ifdef XP_WIN32
  39.  
  40. #define PROC_IImageConversionDialog_Create "IImageConversionDialog_Create"
  41. #define PROC_IIMEDll_Create                "IIMEDll_Create"
  42. #define PROC_ITagDialog_Create             "ITagDialog_Create"
  43. #define PROC_IJPEGOptionsDlg_Create        "IJPEGOptionsDlg_Create"
  44.  
  45. #else //XP_WIN16
  46. #define PROC_IImageConversionDialog_Create "IIMAGECONVERSIONDIALOG_CREATE"
  47. #define PROC_IIMEDll_Create                "IIMEDIALOG_CREATE"
  48. #define PROC_ITagDialog_Create             "ITAGDIALOG_CREATE"
  49. #define PROC_IJPEGOptionsDlg_Create        "IJPEGOPTIONSDLG_CREATE"
  50. #endif
  51.  
  52. CEditorResourceDll::CEditorResourceDll()
  53. {
  54.     // Running under Win3.1, if the default drive is A or B and the disk
  55.     //  was removed, this tries to load from the default drive.
  56.     //  So change to C before loading. (A=1, B=2, C=3)
  57.     if( _getdrive() < 3 ){
  58.         _chdrive(3);
  59.     }
  60.     if (s_refcount)
  61.     {
  62.         s_dllinstance=LoadLibrary(EDITORDLL);
  63.         s_refcount++;
  64.         return;
  65.     }
  66.     else
  67.     {
  68.         s_dllinstance=LoadLibrary(EDITORDLL);
  69.         XP_ASSERT(s_dllinstance);
  70.         s_refcount++;
  71.         if(!s_dllinstance)
  72.             return;
  73.         //retrieve all proc addresses and place them into holders
  74.         s_pimagedialog= (IMAGEDIALOGCONSTRUCTOR)GetProcAddress(s_dllinstance,PROC_IImageConversionDialog_Create);
  75.         XP_ASSERT(s_pimagedialog);
  76.  
  77.         s_ptagdialog= (TAGDIALOGCONSTRUCTOR)GetProcAddress(s_dllinstance,PROC_ITagDialog_Create);
  78.         XP_ASSERT(s_ptagdialog);
  79.  
  80.         s_pimedll= (IMEDLLCONSTRUCTOR)GetProcAddress(s_dllinstance,PROC_IIMEDll_Create);
  81.         XP_ASSERT(s_pimedll);
  82.  
  83.         s_pjpegdialog=(IJPEGDLGCONSTRUCTOR)GetProcAddress(s_dllinstance,PROC_IJPEGOptionsDlg_Create);
  84.         XP_ASSERT(s_pjpegdialog);
  85.     }
  86. }
  87.  
  88. CEditorResourceDll::~CEditorResourceDll()
  89. {
  90. #ifdef WIN32
  91.     if (!FreeLibrary(s_dllinstance))
  92.         XP_ASSERT(0);
  93. #else
  94.     FreeLibrary(s_dllinstance);
  95. #endif
  96.        s_refcount--;
  97. }
  98.  
  99. HINSTANCE
  100. CEditorResourceDll::switchResources()
  101. {
  102.     XP_ASSERT(s_refcount);
  103.     HINSTANCE t_hinstance=AfxGetResourceHandle();
  104.     AfxSetResourceHandle(s_dllinstance);
  105.     return t_hinstance;
  106. }
  107.  
  108.  
  109.  
  110. IImageConversionDialog *
  111. CEditorResourceDll::CreateImageConversionDialog(HWND pParent/*=NULL*/)
  112. {
  113.     XP_ASSERT(s_pimagedialog);
  114.     if (!s_pimagedialog)
  115.         return NULL;
  116.     return (*s_pimagedialog)(pParent);
  117. }
  118.  
  119. ITagDialog *
  120. CEditorResourceDll::CreateTagDialog(IWFEInterface * wfe, IEDTInterface * edt, HWND hwnd,char * pchar)
  121. {
  122.     XP_ASSERT(s_ptagdialog);
  123.     if (!s_ptagdialog)
  124.         return NULL;
  125.     return (*s_ptagdialog)(wfe,edt,pchar,hwnd);
  126. }
  127.  
  128.  
  129. IIMEDll *
  130. CEditorResourceDll::CreateImeDll()
  131. {
  132.     XP_ASSERT(s_pimedll);
  133.     if (!s_pimedll)
  134.         return NULL;
  135.     return (*s_pimedll)();
  136. }
  137.  
  138. IJPEGOptionsDlg *
  139. CEditorResourceDll::CreateJpegDialog(HWND pParent/*=NULL*/)
  140. {
  141.     XP_ASSERT(s_pjpegdialog);
  142.     if (!s_pjpegdialog)
  143.         return NULL;
  144.     return (*s_pjpegdialog)(pParent);
  145. }
  146.  
  147.  
  148.