⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpippluginifce.cpp

📁 lwip tcp/ip 协议栈 adsp BF533 DSP 移植 用 visual dsp++ 编译
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// TCPIPpluginIfce.cpp : Implementation of CTCPIPpluginIfce

#include "stdafx.h"
#include "TCPIPplugin.h"
#include "TCPIPpluginIfce.h"

#include <afxdlgs.h>
#include "resource.h"


#include "classtemplate.h"
#include "generalpage.h"
#include "NetworkIfce0.h"
#include "NetworkIfce1.h"
#include "ip.h"
#include "tcp.h"
#include "debug.h"
#include "ConfigGen.h"
#include "Memory.h"
#include "reg.h"

GeneralPage  *g_pGP;
NetworkIfce0 *g_pNP0;
NetworkIfce1 *g_pNP1;
IP           *g_pIP;
TCP          *g_pTCP;
Debug        *g_pDEBUG;
Memory       *g_pMEMORY;

// Keeps track of the last opened configuration file
//
char g_last_configfile[512];
bool g_save= false;
extern bool g_load_complete_display;

//////////////////////////////////////////////////////////////////////////////
//	prototypes for the events that we will be sinking
//////////////////////////////////////////////////////////////////////////////

_ATL_FUNC_INFO IADspMenuManagerEvents_OnMenuClickedInfo    = { CC_STDCALL, VT_ERROR, 1, { VT_I2       } };
_ATL_FUNC_INFO IADspProjectListEvents_OnProjectCreatedInfo = { CC_STDCALL, VT_ERROR, 1, { VT_DISPATCH } };
_ATL_FUNC_INFO IADspProjectListEvents_OnProjectAddedInfo   = { CC_STDCALL, VT_ERROR, 1, { VT_DISPATCH } };
_ATL_FUNC_INFO IADspProjectListEvents_OnProjectRemovedInfo = { CC_STDCALL, VT_ERROR, 0                  };

short WM_NEWCLASS = -1; // our custom menu id


///////////////////////////////////////////////////////////////////////////////
// STDMETHODIMP CTCPIPpluginIfce::InPlaceActivate( LONG, const RECT* )
//
// This method is invoked when the plugin is first created and is where all
// VisualDSP++ Automation objects should be created and/or attached to.
///////////////////////////////////////////////////////////////////////////////

STDMETHODIMP CTCPIPpluginIfce::InPlaceActivate( LONG iVerb, const RECT* pRect )
{
	// make sure that we are using our resources
	AFX_MANAGE_STATE( AfxGetStaticModuleState() );

	try
	{
		// connect to the IDDE
		m_pApp.CreateInstance( "VisualDSP.ADspApplication" );
		
		if( m_pApp == NULL ) throw _com_error(E_FAIL);

		// save the objects that we will be using
		m_pMenuMgr = m_pApp->MenuManager;
		m_pProjectList = m_pApp->ProjectList;

		// add our menu item
		WM_NEWCLASS = m_pMenuMgr->AddMenuTail( "&Settings:&TCP/IP Configuration...", 
											   "Configures the lwIP TCP/IP stack" );

		// advise the objects that we are interested in receiving event notifications
		ADspMenuManagerEventHandler::DispEventAdvise( m_pMenuMgr );
		ADspProjectListEventHandler::DispEventAdvise( m_pProjectList );

		// disable the menu item if there are no projects currently loaded
		if( m_pApp->ProjectList->Count == 0 )
			m_pMenuMgr->EnableMenuItem( WM_NEWCLASS, FALSE );
	}
	catch( _com_error err )
	{
		ASSERT( !" CTCPIPpluginIfce::InPlaceActivate() Failed!" );
	}

	return CComControlBase::InPlaceActivate( iVerb, pRect );
}

///////////////////////////////////////////////////////////////////////////////
// STDMETHODIMP CTCPIPpluginIfce::InPlaceDeactivate()
//
// This method is invoked when the plugin is about to be destroyed.  Release
// all VisualDSP++ Automation objects and/or other resources here.
///////////////////////////////////////////////////////////////////////////////

STDMETHODIMP CTCPIPpluginIfce::InPlaceDeactivate()
{
	// make sure that we are using our resources
	AFX_MANAGE_STATE( AfxGetStaticModuleState() );

	try
	{
		// we're about to be destroyed so release any objects that 
		// we are maintaining references to.

		if( m_pMenuMgr != NULL ) 
		{
			// stop receiving menu events
			ADspMenuManagerEventHandler::DispEventUnadvise( m_pMenuMgr );
			m_pMenuMgr.Release();
		}

		if( m_pProjectList != NULL ) 
		{
			// stop receiving projectlist events
			ADspProjectListEventHandler::DispEventUnadvise( m_pProjectList );
			m_pProjectList.Release();
		}

		if( m_pApp != NULL ) 
		{
			// always release the app object last
			m_pApp.Release();
		}
	}
	catch( _com_error err )
	{
		ASSERT( !" CTCPIPpluginIfce::InPlaceDeactivate() Failed!" );
	}
	
	return IOleInPlaceObjectWindowlessImpl<CTCPIPpluginIfce>::InPlaceDeactivate();
}

///////////////////////////////////////////////////////////////////////////////
// STDMETHODIMP CTCPIPpluginIfce::OpenFile( BOOL, long )
//
// This method is automatically called when the user opens a file with any
// of the following extensions:
//
// .tcp
//
// szFileName contains the full path to the file to open.
///////////////////////////////////////////////////////////////////////////////

STDMETHODIMP CTCPIPpluginIfce::OpenFile( BSTR fname )
{
	// make sure that we are using our resources
	AFX_MANAGE_STATE( AfxGetStaticModuleState() );

	CString fn = fname;
	char filename[512];

	strcpy(filename,fn);

	OpenDialog(filename);

	return S_OK;
}


///////////////////////////////////////////////////////////////////////////////
// STDMETHODIMP CTCPIPpluginIfce::OpenFile2( LPDISPATCH FileName )
//
// This method is automatically called when the user opens a file with any
// of the following extensions:
//
// .tcp
//
// FileName contains the full path to the file to open.
///////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CTCPIPpluginIfce::OpenFile2( LPDISPATCH FileName )
{
	IADspSourceFilePtr pTCPSourceFile = FileName;

	BSTR bstrFileName;
	HRESULT hr = pTCPSourceFile->get_FileName(&bstrFileName);
	if (SUCCEEDED(hr)) {
		// save the parent project and open the .TCP file
		OpenFile( bstrFileName );
	}

	return S_OK;
}

//////////////////////////////////////////////////////////////////////////////
//	STDMETHODIMP CTCPIPpluginIfce::OnMenuItemClicked( short )
//////////////////////////////////////////////////////////////////////////////

STDMETHODIMP CTCPIPpluginIfce::OnMenuItemClicked( short nId )
{
	char filename[512];

	// make sure that we are using our resources
	AFX_MANAGE_STATE( AfxGetStaticModuleState() );

	if( nId == WM_NEWCLASS )
	{
		IADspProjectPtr pProject = m_pApp->ProjectList->ActiveProject;
		// look for .tcp file in the project
		filename[0] = 0;

		if (pProject != NULL) {
			// scan the files

			for ( long i = 0; i < pProject->Count; i++ ) {
				IADspSourceFilePtr pSourceFile = pProject->GetItem( i );

				if (pSourceFile != NULL) {
					BSTR bstrfn = pSourceFile->FileName;

					CString sfn = bstrfn;

					if (sfn.GetLength()>=4) {
						CString rhs = sfn.Right(4);
						if (rhs.CompareNoCase(".tcp")== 0) {
							// we have found a .tcp file
							strcpy(filename,sfn);
							break;
						}
					}
				}

			}
		}

		OpenDialog(filename);
	}
	return S_OK;
}


//////////////////////////////////////////////////////////////////////////////
//	STDMETHODIMP CTCPIPpluginIfce::OpenDialog( char *filename )
//////////////////////////////////////////////////////////////////////////////
bool CTCPIPpluginIfce::OpenDialog(char *filename)
{
	static char *filter = "TCP/IP Configuration file (*.tcp)\x00*.tcp;\x00\x00";
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#if 0
	char fullfilename[512];
	OPENFILENAME ofn;
	char *filepart=NULL;

	if (filename[0]==0) {
		// prompt for a file

		memset(&ofn,0, sizeof(ofn));
		ofn.lStructSize = sizeof(ofn);
		ofn.lpstrFilter = filter;
		ofn.lpstrFile = filename;
		ofn.nMaxFile = sizeof(filename);
		ofn.lpstrTitle = "Open TCP/IP configuration file";
		ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;

		if(GetOpenFileName(&ofn))
		{
			strcpy(filename,ofn.lpstrFile);
		
		}
		else
			filename[0] = 0;
	}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -