home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2005 May
/
CMCD0505.ISO
/
Software
/
Shareware
/
Comunicatii
/
netmansuite
/
setup.exe
/
Samples
/
VisualC
/
Plugin.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2001-05-23
|
6KB
|
212 lines
// Plugin.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "Plugin.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CPluginApp
BEGIN_MESSAGE_MAP(CPluginApp, CWinApp)
//{{AFX_MSG_MAP(CPluginApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPluginApp construction
CPluginApp::CPluginApp()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_pPropsDlg = NULL;
m_pPrefsDlg = NULL;
m_iPrefsValue = GetPrivateProfileInt("General", "Preferences value", 0, GetStartDir() + "\\plugin1000.ini");
}
CString CPluginApp::GetStartDir()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
char pszFileName[MAX_PATH + 1];
CString sResult;
int i;
// retrieving name of the DLL file
GetModuleFileName(AfxGetApp()->m_hInstance, pszFileName, MAX_PATH);
// removing file name
sResult = pszFileName;
for (i=sResult.GetLength()-1; i>=0; i--)
if (sResult[i] == 92)
{
sResult = sResult.Left(i);
break;
}
if (sResult.Find("\\Plugins\\") != -1)
sResult = sResult.Left(sResult.Find("\\Plugins\\") + 1);
return sResult;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CPluginApp object
CPluginApp theApp;
void PASCAL __stdcall GetInfo(KHW_PLUGIN_INFO *pPluginInfo)
{
if (!pPluginInfo)
return;
pPluginInfo->m_dVersion = 2.6;
pPluginInfo->m_iID = 1000;
strcpy(pPluginInfo->m_szName, "Sample plugin");
strcpy(pPluginInfo->m_szCheckName, "Sample plugin");
strcpy(pPluginInfo->m_szPropertiesTabTitle, "Sample");
strcpy(pPluginInfo->m_szPreferencesTabTitle, "Sample");
}
void PASCAL __stdcall BeginEditProperties(KHW_PLUGIN_DATA *pPluginData)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (!pPluginData)
return;
theApp.m_pPropsDlg = new CPropsDlg;
theApp.m_pPropsDlg->m_iPrefsValue = theApp.m_iPrefsValue;
if (pPluginData->m_iDataLen == sizeof(int))
theApp.m_pPropsDlg->m_iPropsValue = *(int*)pPluginData->m_pData;
else
theApp.m_pPropsDlg->m_iPropsValue = 0;
theApp.m_pPropsDlg->Create(CPropsDlg::IDD, CWnd::FromHandle(pPluginData->m_wndParent));
}
void PASCAL __stdcall GetProperties(KHW_PLUGIN_DATA *pPluginData)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (!pPluginData)
return;
if (pPluginData->m_iDataLen)
{
free(pPluginData->m_pData);
pPluginData->m_pData = NULL;
pPluginData->m_iDataLen = 0;
}
theApp.m_pPropsDlg->UpdateData(TRUE);
pPluginData->m_iDataLen = sizeof(int);
pPluginData->m_pData = malloc(sizeof(int));
CopyMemory(pPluginData->m_pData, (void*)&theApp.m_pPropsDlg->m_iPropsValue, sizeof(int));
CString sBuffer;
sBuffer.Format("%d >= %d ?", theApp.m_pPropsDlg->m_iPropsValue, theApp.m_iPrefsValue);
strcpy(pPluginData->m_szDisplayString, sBuffer.GetBuffer(0));
}
void PASCAL __stdcall EndEditProperties(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
theApp.m_pPropsDlg->DestroyWindow();
delete theApp.m_pPropsDlg;
theApp.m_pPropsDlg = NULL;
}
int PASCAL __stdcall CheckServer(KHW_PLUGIN_CHECK_DATA *pPluginData)
{
if (
(!pPluginData) ||
(!pPluginData->m_iDataLen) ||
(pPluginData->m_iDataLen != sizeof(int))
)
{
pPluginData->m_szError = (char*)malloc(strlen("Bad parameters") + 1);
strcpy(pPluginData->m_szError, "Bad parameters");
return 0;
}
if (*(int*)pPluginData >= theApp.m_iPrefsValue)
{
pPluginData->m_szError = (char*)malloc(strlen("Success") + 1);
strcpy(pPluginData->m_szError, "Success");
return 1;
}
else
{
pPluginData->m_szError = (char*)malloc(strlen("The properties value is less then the preferences value") + 1);
strcpy(pPluginData->m_szError, "The properties value is less then the preferences value");
return 0;
}
}
void PASCAL __stdcall BeginEditPreferences(HWND hwndParent)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (!hwndParent)
return;
theApp.m_pPrefsDlg = new CPrefsDlg;
theApp.m_pPrefsDlg->m_iPrefsValue = theApp.m_iPrefsValue;
theApp.m_pPrefsDlg->Create(CPrefsDlg::IDD, CWnd::FromHandle(hwndParent));
}
void PASCAL __stdcall EndEditPreferences()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
theApp.m_pPrefsDlg->DestroyWindow();
delete theApp.m_pPrefsDlg;
theApp.m_pPrefsDlg = NULL;
}
void PASCAL __stdcall ReleaseMemory(void* pMemory, int iLen)
{
free(pMemory);
}
void PASCAL __stdcall SavePreferences()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
theApp.m_pPrefsDlg->UpdateData(TRUE);
theApp.m_iPrefsValue = theApp.m_pPrefsDlg->m_iPrefsValue;
CString sValue;
sValue.Format("%d", theApp.m_iPrefsValue);
WritePrivateProfileString("General", "Preferences value", sValue, theApp.GetStartDir() + "\\plugin1000.ini");
}