home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / EXPERTS.CPP < prev    next >
C/C++ Source or Header  |  1997-01-16  |  9KB  |  324 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\sharemem.hpp>
  3. #include <vcl\vcl.h>
  4. #pragma hdrstop
  5. //---------------------------------------------------------------------------
  6. //   Important note about DLL memory management:
  7. //
  8. //   If your DLL exports any functions that pass String objects (or structs/
  9. //   classes containing nested Strings) as parameter or function results,
  10. //   you will need to add the library BCBMM.LIB to both the DLL project and any
  11. //   EXE projects that use the DLL.  This will change the DLL and its calling
  12. //   EXE's to use the BCBMM.DLL as their memory manager.  In these cases,
  13. //   the file BCBMM.DLL should be deployed along with your DLL.
  14. //
  15. //   To avoid using BCBMM.DLL, pass string information using "char *" or
  16. //   ShortString parameters.
  17. //---------------------------------------------------------------------------
  18. USERES("experts.res");
  19. USEFORM("filters.cpp", FilterDlg);
  20. USEFORM("dlg.cpp", DlgExpert);
  21. USEFORM("app.cpp", AppExpert);
  22. USERC("exptbmps.rc");
  23. USERC("strings.rc");
  24. USELIB("Bcbmm.lib");
  25. //---------------------------------------------------------------------------
  26. #include <ShareMem.hpp>
  27. #include <Forms.hpp>
  28. #include <Windows.hpp>
  29. #include <ExptIntf.hpp>
  30. #include <ToolIntf.hpp>
  31. #include <VirtIntf.hpp>
  32. #include <SysUtils.hpp>
  33.  
  34. #include "Exconst.h"       // external constants
  35. #include "Dlg.h"           // dialogbox expert
  36. #include "App.h"           // application expert
  37.  
  38. #pragma resource "*.RES"
  39.  
  40. String       s;             // utilty String object
  41. String       *ss;
  42. TExpertState tx;
  43. HINSTANCE    instance;
  44.  
  45. /////////////////////////////////////////// TDialogExpert ///////
  46. class __declspec(delphiclass) TDialogExpert;
  47. class TDialogExpert: public TIExpert {
  48.      typedef TIExpert inherited;
  49.   public:
  50.     String __stdcall GetName(void);
  51.     String __stdcall GetComment(void);
  52.     HICON __stdcall GetGlyph(void);
  53.     TExpertStyle __stdcall GetStyle(void);
  54.     TExpertState __stdcall GetState(void);
  55.     String __stdcall GetIDString(void);
  56.     String __stdcall GetAuthor(void);
  57.     String __stdcall GetPage(void);
  58.     String __stdcall GetMenuText(void) { return NULL; }
  59.     void __stdcall Execute(void);
  60.  
  61.     // This is required to realize the linkage; without it we
  62.     // don't get a virtual table. This has something to do with
  63.     // the implicit derivation of TIExpert from VCL's TObject.
  64.     __fastcall TDialogExpert(void) {}
  65.     __fastcall ~TDialogExpert(void) {}
  66. };
  67.  
  68. /////////////////////////////////////////// TApplicationExpert //
  69. class __declspec(delphiclass) TApplicationExpert;
  70. class TApplicationExpert: public TIExpert {
  71.      typedef TIExpert inherited;
  72.   public:
  73.     String __stdcall GetName(void);
  74.     String __stdcall GetComment(void);
  75.     HICON __stdcall GetGlyph(void);
  76.     TExpertStyle __stdcall GetStyle(void);
  77.     TExpertState __stdcall GetState(void);
  78.     String __stdcall GetIDString(void);
  79.     String __stdcall GetAuthor(void);
  80.     String __stdcall GetPage(void);
  81.     String __stdcall GetMenuText(void) { return NULL; }
  82.     void __stdcall Execute(void);
  83.  
  84.     // This is required to realize the linkage; without it we
  85.     // don't get a virtual table
  86.     __fastcall TApplicationExpert(void) {}
  87.     __fastcall ~TApplicationExpert(void) {}
  88. };
  89.  
  90. String Author("Borland");
  91. String DlgID("Borland.DlgExpertDemo");
  92. String AppID("Borland>AppExpertDemo");
  93.  
  94. //---------------------------------------------------------------
  95. void HandleException(void)
  96. {
  97.   ToolServices->RaiseException(ReleaseException());
  98. } // end of HandleException()
  99.  
  100. //========================================= TDialogExpert =======
  101. String __stdcall TDialogExpert::GetName(void)
  102. {
  103.   try
  104.   {
  105.     s = LoadStr(sDlgExpertName);
  106.   } catch(...)
  107.   {
  108.     HandleException();
  109.   }
  110.   return s;
  111. } // end of TDialogExpert::GetName()
  112.  
  113. //========================================= TDialogExpert =======
  114. String __stdcall TDialogExpert::GetComment(void)
  115. {
  116.   try
  117.   {
  118.     s = LoadStr(sDlgExpertDesc);
  119.   } catch(...)
  120.   {
  121.     HandleException();
  122.   }
  123.   return s;
  124. } // end of TDialogExpert::GetComment()
  125.  
  126. //========================================= TDialogExpert =======
  127. HICON __stdcall TDialogExpert::GetGlyph(void)
  128. {
  129.   HICON icon;
  130.   try
  131.   {
  132.     icon = LoadIcon((void*)HInstance, "DLGEXPT");
  133.   } catch(...)
  134.   {
  135.     HandleException();
  136.   }
  137.   return icon;
  138. } // end of TDialogExpert::GetGlyph()
  139.  
  140. //========================================= TDialogExpert =======
  141. TExpertStyle __stdcall TDialogExpert::GetStyle(void)
  142. {
  143.   return esForm;
  144. } // end of TDialogExpert::GetStyle()
  145.  
  146. //========================================= TDialogExpert =======
  147. TExpertState __stdcall TDialogExpert::GetState(void)
  148. {
  149.   tx << esEnabled;
  150.   return tx;
  151. } // end of TDialogExpert::GetState()
  152.  
  153. //========================================= TDialogExpert =======
  154. String __stdcall TDialogExpert::GetIDString(void)
  155. {
  156.   return DlgID;
  157. } // end of TDialogExpert::GetIDString()
  158.  
  159. //========================================= TDialogExpert =======
  160. String __stdcall TDialogExpert::GetAuthor(void)
  161. {
  162.   return Author;
  163. } // end of TDialogExpert::GetAuthor()
  164.  
  165. //========================================= TDialogExpert =======
  166. String __stdcall TDialogExpert::GetPage(void)
  167. {
  168.   try
  169.   {
  170.     s = LoadStr(sDialogsPage);
  171.   } catch(...)
  172.   {
  173.     HandleException();
  174.   }
  175.   return s;
  176. } // end of TDialogExpert::GetPage()
  177.  
  178. //========================================= TDialogExpert =======
  179. void __stdcall TDialogExpert::Execute(void)
  180. {
  181.   try
  182.   {
  183.     DialogExpert(ToolServices);
  184.   } catch(...)
  185.   {
  186.     HandleException();
  187.   }
  188. } // end of TDialogExpert::Execute()
  189.  
  190. //========================================= TApplicationExpert ==
  191. String __stdcall TApplicationExpert::GetName(void)
  192. {
  193.   try
  194.   {
  195.     s = LoadStr(sAppExpertName);
  196.   } catch(...)
  197.   {
  198.     HandleException();
  199.   }
  200.   return s;
  201. } // end of TApplicationExpert::GetName()
  202.  
  203. //========================================= TApplicationExpert ==
  204. String __stdcall TApplicationExpert::GetComment(void)
  205. {
  206.   try
  207.   {
  208.     s = LoadStr(sAppExpertDesc);
  209.   } catch(...)
  210.   {
  211.     HandleException();
  212.   }
  213.   return s;
  214. } // end of TApplicationExpert::GetComment()
  215.  
  216. //========================================= TApplicationExpert ==
  217. HICON __stdcall TApplicationExpert::GetGlyph(void)
  218. {
  219.   HICON glyph;
  220.   try
  221.   {
  222.     glyph = LoadIcon((void*)HInstance, "APPEXPT");
  223.   } catch(...)
  224.   {
  225.     HandleException();
  226.   }
  227.   return glyph;
  228. } // end of TApplicationExpert::GetGlyph()
  229.  
  230. //========================================= TApplicationExpert ==
  231. TExpertStyle __stdcall TApplicationExpert::GetStyle(void)
  232. {
  233.   return esProject;
  234. } // end of TApplicationExpert::GetStyle()
  235.  
  236. //========================================= TApplicationExpert ==
  237. TExpertState __stdcall TApplicationExpert::GetState(void)
  238. {
  239.   tx << esEnabled;
  240.   return tx;
  241. } // end of TApplicationExpert::GetState()
  242.  
  243. //========================================= TApplicationExpert ==
  244. String __stdcall TApplicationExpert::GetIDString(void)
  245. {
  246.   return AppID;
  247. } // end of TApplicationExpert::GetIDString()
  248.  
  249. //========================================= TApplicationExpert ==
  250. String __stdcall TApplicationExpert::GetAuthor(void)
  251. {
  252.   return Author;
  253. } // end of TApplicationExpert::GetAuthor()
  254.  
  255. //========================================= TApplicationExpert ==
  256. String __stdcall TApplicationExpert::GetPage(void)
  257. {
  258.   try
  259.   {
  260.     s = LoadStr(sProjectsPage);
  261.   } catch(...)
  262.   {
  263.     HandleException();
  264.   }
  265.   return s;
  266. } // end of TApplicationExpert::GetPage()
  267.  
  268. //========================================= TApplicationExpert ==
  269. void __stdcall TApplicationExpert::Execute(void)
  270. {
  271.   try
  272.   {
  273.     ApplicationExpert(ToolServices);
  274.   } catch(...)
  275.   {
  276.     HandleException();
  277.   }
  278. } // end of TApplicationExpert::Execute()
  279.  
  280. //---------------------------------------------------------------
  281. extern "C" __declspec(dllexport) void __fastcall DoneExpert(void)
  282. {
  283.   // Put any general destruction code here.  Note that the
  284.   // IDE will destroy any experts which have been registered.
  285. }
  286.  
  287. //---------------------------------------------------------------
  288. extern "C" __declspec(dllexport) bool _stdcall INITEXPERT0016(TIToolServices* ToolServices,
  289.                                                TExpertRegisterProc RegisterProc,
  290.                                                TExpertTerminateProc &Terminate)
  291. {
  292.   // make sure we"re the first and only instance
  293.   int Result = Exptintf::ToolServices == NULL;
  294.   if (!Result) return false;
  295.  
  296.   Exptintf::ToolServices = ToolServices;
  297.   if (ToolServices != NULL)
  298.     Application->Handle = ToolServices->GetParentHandle();
  299.   else
  300.     return false;
  301.  
  302.   Terminate = DoneExpert;
  303.  
  304.   // register the experts
  305.   TDialogExpert *de = new TDialogExpert;
  306.   TApplicationExpert *ae = new TApplicationExpert;
  307.   (*RegisterProc)(de);
  308.   (*RegisterProc)(ae);
  309.  
  310.   return true;
  311. } // end of InitExpert()
  312.  
  313. //***************************************************************
  314. extern "C" __declspec(dllexport) int WINAPI DllEntryPoint(HINSTANCE hinst,
  315.                                                unsigned long reason,
  316.                                                void*)
  317. {
  318.   instance = hinst;
  319.   return 1;
  320. }
  321. //---------------------------------------------------------------
  322.  
  323.  
  324.