home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 May / CMCD0505.ISO / Software / Shareware / Comunicatii / netmansuite / setup.exe / Samples / VisualC / Plugin.cpp < prev    next >
C/C++ Source or Header  |  2001-05-23  |  6KB  |  212 lines

  1. // Plugin.cpp : Defines the initialization routines for the DLL.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Plugin.h"
  6.  
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13. //
  14. //    Note!
  15. //
  16. //        If this DLL is dynamically linked against the MFC
  17. //        DLLs, any functions exported from this DLL which
  18. //        call into MFC must have the AFX_MANAGE_STATE macro
  19. //        added at the very beginning of the function.
  20. //
  21. //        For example:
  22. //
  23. //        extern "C" BOOL PASCAL EXPORT ExportedFunction()
  24. //        {
  25. //            AFX_MANAGE_STATE(AfxGetStaticModuleState());
  26. //            // normal function body here
  27. //        }
  28. //
  29. //        It is very important that this macro appear in each
  30. //        function, prior to any calls into MFC.  This means that
  31. //        it must appear as the first statement within the 
  32. //        function, even before any object variable declarations
  33. //        as their constructors may generate calls into the MFC
  34. //        DLL.
  35. //
  36. //        Please see MFC Technical Notes 33 and 58 for additional
  37. //        details.
  38. //
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CPluginApp
  42.  
  43. BEGIN_MESSAGE_MAP(CPluginApp, CWinApp)
  44.     //{{AFX_MSG_MAP(CPluginApp)
  45.         // NOTE - the ClassWizard will add and remove mapping macros here.
  46.         //    DO NOT EDIT what you see in these blocks of generated code!
  47.     //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CPluginApp construction
  52.  
  53. CPluginApp::CPluginApp()
  54. {
  55.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  56.     m_pPropsDlg   = NULL;
  57.     m_pPrefsDlg   = NULL;
  58.     m_iPrefsValue = GetPrivateProfileInt("General", "Preferences value", 0, GetStartDir() + "\\plugin1000.ini");
  59. }
  60.  
  61. CString CPluginApp::GetStartDir()
  62. {
  63.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  64.  
  65.     char pszFileName[MAX_PATH + 1];
  66.     CString sResult;
  67.     int i;
  68.  
  69. //    retrieving name of the DLL file
  70.     GetModuleFileName(AfxGetApp()->m_hInstance, pszFileName, MAX_PATH);
  71.  
  72. //    removing file name
  73.     sResult = pszFileName;
  74.     for (i=sResult.GetLength()-1; i>=0; i--)
  75.         if (sResult[i] == 92)
  76.         {
  77.             sResult = sResult.Left(i);
  78.             break;
  79.         }
  80.     if (sResult.Find("\\Plugins\\") != -1)
  81.         sResult = sResult.Left(sResult.Find("\\Plugins\\") + 1);
  82.  
  83.     return sResult;
  84. }
  85.  
  86. /////////////////////////////////////////////////////////////////////////////
  87. // The one and only CPluginApp object
  88.  
  89. CPluginApp theApp;
  90.  
  91. void PASCAL __stdcall GetInfo(KHW_PLUGIN_INFO *pPluginInfo)
  92. {
  93.     if (!pPluginInfo)
  94.         return;
  95.  
  96.     pPluginInfo->m_dVersion = 2.6;
  97.     pPluginInfo->m_iID      = 1000;
  98.     strcpy(pPluginInfo->m_szName, "Sample plugin");
  99.     strcpy(pPluginInfo->m_szCheckName, "Sample plugin");
  100.     strcpy(pPluginInfo->m_szPropertiesTabTitle, "Sample");
  101.     strcpy(pPluginInfo->m_szPreferencesTabTitle, "Sample");
  102. }
  103.  
  104. void PASCAL __stdcall BeginEditProperties(KHW_PLUGIN_DATA *pPluginData)
  105. {
  106.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  107.     if (!pPluginData)
  108.         return;
  109.  
  110.     theApp.m_pPropsDlg = new CPropsDlg;
  111.     theApp.m_pPropsDlg->m_iPrefsValue = theApp.m_iPrefsValue;
  112.     if (pPluginData->m_iDataLen == sizeof(int))
  113.         theApp.m_pPropsDlg->m_iPropsValue = *(int*)pPluginData->m_pData;
  114.     else
  115.         theApp.m_pPropsDlg->m_iPropsValue = 0;
  116.     theApp.m_pPropsDlg->Create(CPropsDlg::IDD, CWnd::FromHandle(pPluginData->m_wndParent));
  117. }
  118.  
  119. void PASCAL __stdcall GetProperties(KHW_PLUGIN_DATA *pPluginData)
  120. {
  121.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  122.     if (!pPluginData)
  123.         return;
  124.     if (pPluginData->m_iDataLen)
  125.     {
  126.         free(pPluginData->m_pData);
  127.         pPluginData->m_pData    = NULL;
  128.         pPluginData->m_iDataLen = 0;
  129.     }
  130.  
  131.     theApp.m_pPropsDlg->UpdateData(TRUE);
  132.     pPluginData->m_iDataLen = sizeof(int);
  133.     pPluginData->m_pData    = malloc(sizeof(int));
  134.     CopyMemory(pPluginData->m_pData, (void*)&theApp.m_pPropsDlg->m_iPropsValue, sizeof(int));
  135.  
  136.     CString sBuffer;
  137.     sBuffer.Format("%d >= %d ?", theApp.m_pPropsDlg->m_iPropsValue, theApp.m_iPrefsValue);
  138.     strcpy(pPluginData->m_szDisplayString, sBuffer.GetBuffer(0));
  139. }
  140.  
  141. void PASCAL __stdcall EndEditProperties(void)
  142. {
  143.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  144.     theApp.m_pPropsDlg->DestroyWindow();
  145.     delete theApp.m_pPropsDlg;
  146.     theApp.m_pPropsDlg = NULL;
  147. }
  148.  
  149. int PASCAL __stdcall CheckServer(KHW_PLUGIN_CHECK_DATA *pPluginData)
  150. {
  151.     if (
  152.         (!pPluginData) ||
  153.         (!pPluginData->m_iDataLen) ||
  154.         (pPluginData->m_iDataLen != sizeof(int))
  155.        )
  156.     {
  157.         pPluginData->m_szError = (char*)malloc(strlen("Bad parameters") + 1);
  158.         strcpy(pPluginData->m_szError, "Bad parameters");
  159.         return 0;
  160.     }
  161.  
  162.     if (*(int*)pPluginData >= theApp.m_iPrefsValue)
  163.     {
  164.         pPluginData->m_szError = (char*)malloc(strlen("Success") + 1);
  165.         strcpy(pPluginData->m_szError, "Success");
  166.         return 1;
  167.     }
  168.     else
  169.     {
  170.         pPluginData->m_szError = (char*)malloc(strlen("The properties value is less then the preferences value") + 1);
  171.         strcpy(pPluginData->m_szError, "The properties value is less then the preferences value");
  172.         return 0;
  173.     }
  174. }
  175.  
  176. void PASCAL __stdcall BeginEditPreferences(HWND hwndParent)
  177. {
  178.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  179.     if (!hwndParent)
  180.         return;
  181.  
  182.     theApp.m_pPrefsDlg = new CPrefsDlg;
  183.     theApp.m_pPrefsDlg->m_iPrefsValue = theApp.m_iPrefsValue;
  184.     theApp.m_pPrefsDlg->Create(CPrefsDlg::IDD, CWnd::FromHandle(hwndParent));
  185. }
  186.  
  187. void PASCAL __stdcall EndEditPreferences()
  188. {
  189.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  190.  
  191.     theApp.m_pPrefsDlg->DestroyWindow();
  192.     delete theApp.m_pPrefsDlg;
  193.     theApp.m_pPrefsDlg = NULL;
  194. }
  195.  
  196. void PASCAL __stdcall ReleaseMemory(void* pMemory, int iLen)
  197. {
  198.     free(pMemory);
  199. }
  200.  
  201. void PASCAL __stdcall SavePreferences()
  202. {
  203.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  204.  
  205.     theApp.m_pPrefsDlg->UpdateData(TRUE);
  206.     theApp.m_iPrefsValue = theApp.m_pPrefsDlg->m_iPrefsValue;
  207.  
  208.     CString sValue;
  209.     sValue.Format("%d", theApp.m_iPrefsValue);
  210.     WritePrivateProfileString("General", "Preferences value", sValue, theApp.GetStartDir() + "\\plugin1000.ini");
  211. }
  212.