📄 tcpippluginifce.cpp
字号:
// here we create the dialog
CPropertySheet config_prop_sheet("TCPIP Configuration");
GeneralPage gp;
NetworkIfce0 np0;
NetworkIfce1 np1;
IP ip;;
TCP tcp;
Debug debug;
Memory mem;
config_prop_sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
config_prop_sheet.AddPage(&gp);
config_prop_sheet.AddPage(&ip);
config_prop_sheet.AddPage(&np0);
config_prop_sheet.AddPage(&np1);
config_prop_sheet.AddPage(&tcp);
config_prop_sheet.AddPage(&debug);
config_prop_sheet.AddPage(&mem);
g_pGP = &gp;
g_pNP0 = &np0;
g_pNP1 = &np1;
g_pIP = &ip;
g_pTCP = &tcp;
g_pDEBUG = &debug;
g_pMEMORY = &mem;
strcpy(g_last_configfile,filename);
if (filename[0]!=0) {
g_pGP->LoadFile(g_last_configfile);
g_save = false;
} else {
g_save = true;
}
gp.m_OriginalFile = filename;
show_again:
int s_ret = config_prop_sheet.DoModal();
if (s_ret == IDOK) {
// Rest the global for the next load.
g_load_complete_display = false;
if (g_save == true)
{
int ret =AfxMessageBox("Do you want to save the changes and update the project files?",MB_ICONEXCLAMATION | MB_ICONWARNING | MB_YESNO);
if(ret == IDYES) {
gp.SaveAsFile(g_last_configfile,false);
}
}
} else {
if (g_save == true)
{
int ret =AfxMessageBox("Do you want to exit without saving the changes and updating the project files?",MB_ICONEXCLAMATION | MB_ICONWARNING | MB_YESNO);
if(ret == IDNO) goto show_again;
}
}
g_save = false;
g_load_complete_display = false;
return true;
}
//////////////////////////////////////////////////////////////////////////////
// STDMETHODIMP CTCPIPpluginIfce::OnProjectAdded( LPDISPATCH )
//////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CTCPIPpluginIfce::OnProjectAdded( LPDISPATCH )
{
try
{
// a project has either been added or created so make sure that
// our menu item is enabled
m_pMenuMgr->EnableMenuItem( WM_NEWCLASS, TRUE );
}
catch( _com_error err )
{
return E_FAIL;
}
return S_OK;
}
//////////////////////////////////////////////////////////////////////////////
// STDMETHODIMP CTCPIPpluginIfce::OnProjectRemoved()
//////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CTCPIPpluginIfce::OnProjectRemoved()
{
try
{
// a project has been closed so make sure that
// our menu item is disabled if there are no projects opened
m_pMenuMgr->EnableMenuItem( WM_NEWCLASS, m_pApp->ProjectList->Count != 0 );
}
catch( _com_error err )
{
return E_FAIL;
}
return S_OK;
}
//////////////////////////////////////////////////////////////////////////////
// BOOL CTCPIPpluginIfce::CreateFiles( LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR )
//////////////////////////////////////////////////////////////////////////////
BOOL CTCPIPpluginIfce::CreateFiles( LPCTSTR szClassName,
LPCTSTR szSourceName,
LPCTSTR szHeaderName,
LPCTSTR szDerivationList )
{
CString csSourceText = g_szSourceTemplate;
CString csHeaderText = g_szHeaderTemplate;
// create a sentry string for the header file (ie: __MYCLASS_H__)
CString csUpperFileName = szHeaderName;
csUpperFileName.Replace( " ", "_" );
csUpperFileName.MakeUpper();
csUpperFileName = csUpperFileName.Left( csUpperFileName.ReverseFind('.') );
CString csDerivationList = szDerivationList;
// if the derivation list is not empty then prepend it with a
// semicolon
if( !csDerivationList.IsEmpty() )
csDerivationList = ": " + csDerivationList;
// replace the template tokens with the real data
csHeaderText.Replace( "%class_name%", szClassName );
csHeaderText.Replace( "%class_sentry%", csUpperFileName );
csHeaderText.Replace( "%derivation_list%", csDerivationList );
csSourceText.Replace( "%class_header%", szHeaderName );
csSourceText.Replace( "%class_name%", szClassName );
try
{
// get the active project
IADspProjectPtr pProject = m_pProjectList->ActiveProject;
CString csSourcePath = szSourceName;
CString csHeaderPath = szHeaderName;
CString csBasePath = static_cast<LPCTSTR>(pProject->FileName);
csBasePath = csBasePath.Left( csBasePath.ReverseFind('\\') + 1 );
// if the user did not specify a fully qualified path then we'll
// create the new files in the same directory as the .dpj file.
if( csSourcePath.FindOneOf(":") != -1 ) csSourcePath = csBasePath + szSourceName;
if( csHeaderPath.FindOneOf(":") != -1 ) csHeaderPath = csBasePath + szHeaderName;
UINT nFlags = (CFile::modeCreate|CFile::modeWrite);
// create the .cpp file
CFile cfSourceFile( csSourcePath, nFlags );
cfSourceFile.Write( csSourceText, csSourceText.GetLength() );
cfSourceFile.Close();
// create the .h file
CFile cfHeaderFile( csHeaderPath, nFlags );
cfHeaderFile.Write( csHeaderText, csHeaderText.GetLength() );
cfHeaderFile.Close();
// add them to the project
pProject->AddFile( LPCTSTR(csSourcePath), "" );
pProject->AddFile( LPCTSTR(csHeaderPath), "" );
// and open them for editing
m_pApp->Documents->Open( LPCTSTR(csHeaderPath) );
m_pApp->Documents->Open( LPCTSTR(csSourcePath) );
}
catch( CFileException* pEx )
{
pEx->Delete();
return FALSE;
}
catch( _com_error err )
{
return FALSE;
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// HRESULT WINAPI CTCPIPpluginIfce::UpdateRegistry(BOOL bRegister)
//
// This method is called when the plugin is registered or unregistered.
///////////////////////////////////////////////////////////////////////////////
HRESULT WINAPI CTCPIPpluginIfce::UpdateRegistry(BOOL bRegister)
{
HRESULT hr = _Module.UpdateRegistryFromResource(IDR_TCPIPPLUGINIFCE, bRegister);
if (FAILED(hr))
return hr;
// use ADI's library for registering/unregistering the plugin
// load ADspCommon.dll which should be located in the same directory as
// the plugin. the plugin must be placed into the VisualDSP\System
// directory
TCHAR szADspCommonPath[MAX_PATH];
szADspCommonPath[0] = 0;
::GetModuleFileName(_Module.m_hInst, szADspCommonPath, sizeof(szADspCommonPath)/sizeof(TCHAR));
// remove the file spec and append ADspCommon.dll
TCHAR *ptr = _tcsrchr( szADspCommonPath, '\\' );
if (ptr) {
*(ptr+1) = 0;
_tcscat( szADspCommonPath, _T( "ADspCommon.dll" ) );
}
HINSTANCE hDLL = LoadLibrary( szADspCommonPath );
if ( hDLL ) {
ADSPCOMMONINITIALIZE pADspCommonInitialize =
(ADSPCOMMONINITIALIZE) GetProcAddress( hDLL, _T("ADspCommonInitialize") );
ADSPCOMMONUNINITIALIZE pADspCommonUninitialize =
(ADSPCOMMONUNINITIALIZE) GetProcAddress( hDLL, _T("ADspCommonUninitialize") );
if (!pADspCommonInitialize || !pADspCommonUninitialize)
return ERROR_PROC_NOT_FOUND;
(*pADspCommonInitialize)( _Module.m_hInst, _T(".") );
if (bRegister) {
ADSPREGISTERPLUGIN pADspRegisterPlugin =
(ADSPREGISTERPLUGIN) GetProcAddress( hDLL, _T("ADspRegisterPlugin") );
if (!pADspRegisterPlugin)
return ERROR_PROC_NOT_FOUND;
// register the plugin
ADSPCOMMON_PLUGININFO PluginInfo;
PluginInfo.pszPluginName = _T("TCP/IP Configuration Manager");
PluginInfo.pszCLSID = _T("{F2BC34EC-FE26-48F6-B9E2-988D0AECC221}");
PluginInfo.bAllowMultipleInstances = FALSE;
PluginInfo.pszDebugProcessorsSupported = _T("ADSP-BF531,ADSP-BF532,ADSP-BF533,ADSP-BF535,ADSP-BF537,ADSP-BF561");
PluginInfo.pszDescription = _T("Configures the lwIP TCP/IP stack");
PluginInfo.bEnabled = FALSE;
PluginInfo.pszFileExtensions = ".tcp";
PluginInfo.pszMenuDescription = _T("Configures TCP/IP stack");
PluginInfo.pszMenuHelpPath = _T("");
PluginInfo.pszMenuItem = _T("");
PluginInfo.pszProjectProcessorsSupported = _T("ADSP-BF531,ADSP-BF532,ADSP-BF533,ADSP-BF535,ADSP-BF537,ADSP-BF561");
PluginInfo.wStartupStyle = 1;
PluginInfo.pszWindowHelpPath = _T("TCPIPPlugin.chm::/html/TCPIPPlugin.htm");
PluginInfo.wWindowType = 0;
(*pADspRegisterPlugin)( &PluginInfo );
}
else {
ADSPUNREGISTERPLUGIN pADspUnregisterPlugin =
(ADSPUNREGISTERPLUGIN) GetProcAddress( hDLL, _T("ADspUnregisterPlugin") );
if (!pADspUnregisterPlugin)
return ERROR_PROC_NOT_FOUND;
(*pADspUnregisterPlugin)( _T("TCP/IP Configuration Manager") );
}
(*pADspCommonUninitialize)();
FreeLibrary( hDLL );
return S_OK;
}
else
return ERROR_DLL_NOT_FOUND;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -