Click here to Skip to main content
12,556,918 members (52,001 online)
Click here to Skip to main content


99 bookmarked

How to write a simple but effective TCP/IP port scanner for Win32

, 27 Oct 2001
An article on how to write a TCP/IP port scanner with a GUI, based on the MFC's property sheet paradigm
	Classe base per la gestione della configurazione tramite il registro (SDK).
	Luca Piergentili, 14/07/99
#ifndef _CCONFIG_H
#define _CCONFIG_H 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "strcpyn.h"
#include "window.h"
#include "CNodeList.h"
#include "CRegKey.h"

#define DEFAULT_REG_KEY "SOFTWARE"				// chiave base

class CConfig
	// tipi interni
	enum TYPE {							// tipo
		NULL_TYPE = -1,					// nullo
		DWORD_TYPE = 0,					// valore numerico
		LPSTR_TYPE = 1						// valore stringa

	union VALUE {							// valore
		DWORD dwValue;						// numero
		char szValue[REGKEY_MAX_KEY_VALUE+1];	// stringa

	// costruttore/distruttore
	virtual ~CConfig();

	// per impostare il flag di modificato
	inline BOOL	GetModified		(void)		{return(m_bDirty);}
	inline void	SetModified		(BOOL bDirty)	{m_bDirty = bDirty;}

	// inserisce il valore nella lista
	BOOL			Insert			(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName,LPCSTR lpcszKeyValue);
	BOOL			Insert			(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName,DWORD dwKeyValue);

	// elimina il valore dalla lista (aggiungere un flag opzionale per eliminare il valore anche dal registro)
	BOOL			Delete			(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName);

	// elimina tutti i valori dalla lista e dal registro
	BOOL			DeleteAll			(LPCSTR lpcszRootKey);
	// restituisce/aggiorna il valore della lista
	inline LPCSTR	GetString			(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName)					{return(String(lpcszSectionName,lpcszKeyName,NULL));}
	inline DWORD	GetNumber			(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName)					{return(Number(lpcszSectionName,lpcszKeyName,(DWORD)-1L));}
	inline LPCSTR	UpdateString		(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName,LPCSTR lpcszKeyValue)	{SetModified(TRUE); return(String(lpcszSectionName,lpcszKeyName,lpcszKeyValue));}
	inline DWORD	UpdateNumber		(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName,DWORD dwKeyValue)		{SetModified(TRUE); return(Number(lpcszSectionName,lpcszKeyName,dwKeyValue));}

	// ricarica il valore dal registro aggiornando la lista
	LPCSTR		ReloadString		(LPCSTR lpcszRootKey,LPCSTR,LPCSTR,LPCSTR defaultvalue = NULL);
	DWORD		ReloadNumber		(LPCSTR lpcszRootKey,LPCSTR,LPCSTR,DWORD = 0L);
	// puntatore all'oggetto per l'accesso al registro
	inline CRegKey* GetRegistry		(void) {return(m_Registry);}

	// crea/elimina la coppia nome/valore dentro la chiave specificata
	BOOL			RegistryCreateValue	(LPCSTR,LPCSTR,LPCSTR);
	BOOL			RegistryCreateValue	(LPCSTR,LPCSTR,DWORD);
	BOOL			RegistryDeleteValue	(LPCSTR,LPCSTR);

	virtual BOOL	Export			(LPCSTR lpcszRootKey,LPCSTR lpcszFileName);
	virtual BOOL	Import			(LPCSTR lpcszRootKey,LPCSTR lpcszFileName);

	// salva/elimina/carica la lista nel/dal registro
	void			Save				(LPCSTR lpcszRootKey);
	void			SaveKey			(LPCSTR lpcszRootKey,LPCSTR lpcszSectionKey,LPCSTR lpcszNameKey);
	void			SaveSection		(LPCSTR lpcszRootKey,LPCSTR lpcszSectionKey);
	void			DeleteSection		(LPCSTR lpcszRootKey,LPCSTR lpcszSectionKey,BOOL bDeleteFromRegistry = FALSE);
	virtual void	Load				(LPCSTR lpcszSectionName = NULL,BOOL bLoadDefaults = FALSE) = 0;

	// oggetto per l'accesso al registro
	CRegKey*		m_Registry;

	BOOL			m_bDirty;

	// gestione del valore della lista
	LPCSTR		String		(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName,LPCSTR lpcszKeyValue = NULL);
	DWORD		Number		(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName,DWORD dwKeyValue = (DWORD)-1L);

	// struttura per l'elemento della lista
	class CONFIG
		// costruttore/distruttore
		CONFIG() {Reset();}
		~CONFIG() {}
		// inizializzazione
		void			Init			(LPCSTR lpcszSectionName = NULL,LPCSTR lpcszKeyName = NULL,LPCSTR lpcszKeyValue = NULL);
		void			Init			(LPCSTR lpcszSectionName = NULL,LPCSTR lpcszKeyName = NULL,DWORD dwKeyValue = (DWORD)-1L);
		void			Reset		(void);
		// copia
		void			SetSection	(LPCSTR lpcszSectionName);
		void			SetName		(LPCSTR lpcszKeyName);
		void			SetValue		(LPCSTR lpcszKeyValue);
		void			SetValue		(DWORD dwKeyValue);
		// recupera
		inline LPCSTR	GetSection	(void)			{return(m_szSection);}
		inline LPCSTR	GetName		(void)			{return(m_szName);}
		inline LPCSTR	GetValue		(LPCSTR = NULL)	{return(m_Value.szValue);}
		inline DWORD	GetValue		(DWORD = 0L)		{return(m_Value.dwValue);}

		// tipo
		inline TYPE	GetType		(void)			{return(m_Type);}
		inline void	SetType		(TYPE type)		{m_Type = type;}

		char		m_szSection[REGKEY_MAX_SECTION_NAME+1];	// nome sezione
		char		m_szName[REGKEY_MAX_KEY_NAME+1];		// nome chiave
		VALUE	m_Value;							// valore
		TYPE		m_Type;							// tipo

	// classe per la gestione della lista
	class CConfigList : public CNodeList
		CConfigList() {}
		virtual ~CConfigList() {CNodeList::DeleteAll();}
		BOOL PreDelete(ITERATOR iter)
				delete ((CONFIG*)iter->data);
				iter->data = (CONFIG*)NULL;
		int Size(void) {return(-1);}
#ifdef _DEBUG
		const char* Signature(void) {return("CConfigList");}

	// oggetto per la gestione della lista
	CConfigList* m_Config;

#endif // _CCONFIG_H

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Luca Piergentili
Web Developer
Italy Italy
I like C and C++, Acid Jazz, James Brown, gli Spaghetti Aglio e Olio, alla Bolognesa, alla Puttanesca e le Fettuccine alla Matriciana ('Maccaroni' over the world). Of course I like beautiful big tits girls too, my little car, Frank Zappa, the art of Zen, italian coffee and much more...

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161026.1 | Last Updated 28 Oct 2001
Article Copyright 2001 by Luca Piergentili
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid