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

📄 lister.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*____________________________________________________________________________
	Copyright (C) 1998 Network Associates, Inc.
	All rights reserved.

	

	$Id: Lister.c,v 1.64.4.1 1999/06/14 05:26:54 philipn Exp $
____________________________________________________________________________*/

/*
 * Lister - Lists all network adapters on the machine
 *          the user selects the desired adapter(s)
 *          then this information is passed on.
 *
 */


/*
 * This is for reference
 *# NetBT\Linkage
 * LanmanServer\Linkage
 * LanmanWorkstation\Linkage
 * RemoteAccess\Linkage
 * NetBIOS\Linkage
 * Tcpip\Linkage
 */
#pragma message( "Compiling " __FILE__ ) 
#pragma message( "Last modified on " __TIMESTAMP__ ) 

#include <windows.h>
#include <windowsx.h>
#include <winreg.h>
#include <commctrl.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h> 
#include <mbstring.h>
#include "resource.h"
#include "Define.h"
#include "Lister.h"
#include "globals.h"

const		DWORD INFINSTALL_PRIMARYINSTALL		= 0x00000001;
const		DWORD INFINSTALL_INPROCINTERP		= 0x00000002;
const		DWORD INFINSTALL_SUPPORTED			= 0x00000003;

/*
 * Program Entry Point
 */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	HKEY		hMainKey	= HKEY_LOCAL_MACHINE;
	HKEY		hOpenKey	= NULL;
	HWND		hwnd;
	MSG			msg;
	WNDCLASSEX	wndclass;
	UINT		nBufferLengthMax = 1024;
	LPBYTE		pData		= NULL;
	DWORD		dwSize;


	/*Ensure Common control Dll is loaded*/
	InitCommonControls();

	bSansCmdLine = FALSE;
	bDelReg		 = FALSE;
	bRunOnce	 = FALSE;

	if (IsCorrectVersion() == FALSE)
	{
		MessageBox (GetFocus(), WRONGOS, szAppName, 0 | MB_ICONERROR);
		exit(0);
	}/*if*/

	/*check the command line*/
	bSilentInstall = FALSE;

	/*void cmdline is ran from runonce
	  this is to fix the problem with 
	  the sys32 dir. poping up when 
	  the runonce contains a value
	  but no data*/
	if (strcmp(szCmdLine, "void") == 0)
		exit(0);
	if (strcmp(szCmdLine, INSTALL) == 0)
		goto begin;
	if (strcmp(szCmdLine, "") == 0)
	{
		bSansCmdLine = TRUE;
		goto begin;
	}/*if*/
	if (strcmp(szCmdLine, "runonce") == 0)
	{
		bSansCmdLine = TRUE;
		bRunOnce = TRUE;
		goto begin;
	}/*if*/
	else if (strcmp(szCmdLine, INSTALLSILENT) == 0)
	{
		bSilentInstall = TRUE;
		goto begin;
	}/*elseif*/
	else if (strcmp(szCmdLine, BINDREVIEW) == 0)
	{
		hwnd = GetDesktopWindow();
		BindReview(hwnd);
		goto done;
	}/*elseif*/
	else if (strcmp(szCmdLine, ADDINF) == 0)
	{
		RemoveInf();
		AddInf();
		goto done;
	}/*elseif*/
	else if (strcmp(szCmdLine, REMOVEINF) == 0)
	{
		RemoveInf();
		goto done;
	}/*elseif*/
	else if (strstr(szCmdLine, DELREG) != NULL)
	{
		RemoveInf();
		PutSAinRunKey();
		dwSize = 1024;
		pData = (LPBYTE) calloc(sizeof(BYTE), dwSize);
		if (RegOpenKeyEx(hMainKey, RUNONCE, 0, KEY_ALL_ACCESS, &hOpenKey)
		== ERROR_SUCCESS)	
			if (RegQueryValueEx(hOpenKey, "PGPnetNeedsReboot", 0,
							  NULL, pData, &dwSize) != ERROR_SUCCESS)
			{
				NeedReboot();
				bDelReg = TRUE;
				RemoveInfFile();
				RemoveNT();
				RemoveInf();
			}/*if*/
		free (pData);
		RegCloseKey(hOpenKey);
		goto done;
	}/*elseif*/
	else if (strcmp(szCmdLine, UNINSTALL) == 0)		     
	{
		if (bIsNT)
		{
			RemoveInf();
			RemoveInfFile();
			RemoveNT();
		}
		else
		{
			Remove95(CLASSNETTRANS, 0);
			Remove95(ROOTNET, 1);
			Remove95(CLASSNET, 0);
		}/*else*/
		goto done;
	}/*elseif*/

//usageerror
	MessageBox (GetFocus(), USAGEERROR, "", 0 | MB_ICONERROR);
	goto done;
	
		
begin: 
	/*Get global instance handle*/
	g_hInstance = hInstance;

	/* Setup new window class */
	ZeroMemory(&wndclass, sizeof(wndclass));

	wndclass.cbSize			= sizeof(wndclass);
	wndclass.style			= CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc	= WndProc;
	wndclass.cbClsExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hInstance		= hInstance;
	wndclass.hIcon			= LoadIcon(hInstance, "lister");
	wndclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground	= (HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName	= NULL;
	wndclass.lpszClassName	= szAppName;
	wndclass.hIconSm		= LoadIcon(hInstance, "lister");

	/* Register the window class */
	RegisterClassEx(&wndclass);

    //Is there another version of this application running? If so, 
    //  we just bring it to the foreground.
    hwnd = FindWindow (szAppName, NULL);
    if (hwnd) 
    {
        //Found another one!
        if (IsIconic(hwnd)) 
        {
            ShowWindow(hwnd, SW_RESTORE);
        }/*if*/
        SetForegroundWindow (hwnd);
        return FALSE;
    }/*if*/

	/* Create a window using the new window class */
	hwnd = CreateWindow(szAppName,				// window class name
				szAppName,						// window caption
				WS_OVERLAPPEDWINDOW,			// window style
				CW_USEDEFAULT,					// initial x position
				CW_USEDEFAULT,					// initial y position
				CW_USEDEFAULT,					// initial x size
				CW_USEDEFAULT,					// initial y size
				NULL,							// parent window handle
				NULL,							// window menu handle
				hInstance,						// program instance handle
				NULL);							// creation parameters

	/* Start the message loop */
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}/*while*/
	return msg.wParam;

done:
	return FALSE;
}/*end*/


/*
 * Window Procedure
 */
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
	/* Use message cracker macros to process messages */
	switch (iMsg)
	{
		case WM_CREATE:
			return HANDLE_WM_CREATE(hwnd, wParam, lParam, Lister_OnCreate);

		case WM_DESTROY:
			return HANDLE_WM_DESTROY(hwnd, wParam, lParam, Lister_OnDestroy);

        case WM_QUIT:
			//Cleanup
			ImageList_Destroy(g_hImages);
			PostQuitMessage(0);
            return TRUE;
	}/*switch*/
	return DefWindowProc(hwnd, iMsg, wParam, lParam);
}/*end*/


/*
 * ListerDlgProc Dialog Procedure
 */
BOOL CALLBACK ListerDlgProc (HWND hwndListerDlg, UINT imsg, WPARAM wParam, LPARAM lParam)
{
	HWND	hListControl = NULL;
	HWND	hOkButton	 = NULL;
	HWND	hHelpButton  = NULL;

	switch (imsg)
    {
		case WM_INITDIALOG:
			HANDLE_WM_INITDIALOG(hwndListerDlg, wParam, lParam, Lister_InitDialog);
			return TRUE;

		case WM_COMMAND:
			HANDLE_WM_COMMAND(hwndListerDlg, wParam, lParam, Lister_OnCommand);
			return TRUE;

		case WM_PAINT:
			//load the question mark icon for the help button
			ghIcon = LoadImage(g_hInstance, MAKEINTRESOURCE (IDI_QMARK), IMAGE_ICON,
					0, 0, LR_DEFAULTCOLOR);
			hHelpButton = GetDlgItem(hwndListerDlg, IDB_HELP);
			SendMessage(hHelpButton, BM_SETIMAGE, (WPARAM)IMAGE_ICON ,(LPARAM)(HANDLE)ghIcon);
			return DefWindowProc(hwndListerDlg, imsg, wParam, lParam);

		case WM_NOTIFY:
			if ((((LPNMHDR) lParam)->code) == LVN_ITEMCHANGED)
			{
				hListControl = GetDlgItem(hwndListerDlg, IDC_ADAPTERLIST);
				hOkButton = GetDlgItem(hwndListerDlg, IDB_PGPNETOK);

				if (SetSelectedItems (hListControl, FALSE))
				{
					Button_Enable(hOkButton, TRUE);
				}/*if*/
				else
				{
					Button_Enable(hOkButton, FALSE);
				}/*else*/
			}/*if*/
			return TRUE;
				
        case WM_QUIT:
			//Cleanup
			ImageList_Destroy(g_hImages);
			EndDialog(hwndListerDlg,0);
		   	PostQuitMessage(0);
            return TRUE;
	
		default:
			return FALSE;
    }/*switch*/
return FALSE;
}/*end*/


/*
 * HelpDlgProc Dialog Procedure
 */
BOOL CALLBACK HelpDlgProc (HWND hwndHelpDlg, UINT imsg, WPARAM wParam, LPARAM lParam)
{
	LPTSTR lpBuffer;

	switch (imsg)
    {
		case WM_COMMAND:
			switch (wParam)
			{
				case IDB_HELPOK:
					EndDialog(hwndHelpDlg,0);
					return TRUE;

			}/*switch*/

		case WM_PAINT:
			lpBuffer = malloc(1024);
			LoadString(g_hInstance,IDS_HELPSTRING, lpBuffer, 1024);
			//SetText
			SetDlgItemText(hwndHelpDlg, IDC_HELPTEXT, lpBuffer);
			free (lpBuffer);
			return DefWindowProc(hwndHelpDlg, imsg, wParam, lParam);

		default:
			return FALSE;
    }/*switch*/
return FALSE;
}/*end*/


/*
 * RebindDlgProc Dialog Procedure
 */
BOOL CALLBACK RebindDlgProc (HWND hwndRebindDlg, UINT imsg, WPARAM wParam, LPARAM lParam)
{
	LPTSTR lpBuffer;


	switch (imsg)
    {
		case WM_COMMAND:
			switch (wParam)
			{
				case IDB_REBINDOK:
					RemoveInf();
					EndDialog(hwndRebindDlg,0);
					RemoveInfFile();
					bDelReg = TRUE;
					RemoveNT();
					RebootYesNo();
					exit(0);
					return TRUE;

				case IDB_REBINDCANCEL:
					EndDialog(hwndRebindDlg,0);
					exit(0);
					return TRUE;
			}/*switch*/

		case WM_PAINT:
			lpBuffer = malloc(1024);

			LoadString(g_hInstance,IDS_REBINDSTRING, lpBuffer, 1024);
			//SetText
			SetDlgItemText(hwndRebindDlg, IDC_REBINDTEXT, lpBuffer);

			LoadString(g_hInstance,IDS_REBINDSTRINGB, lpBuffer, 1024);
			//SetText
			SetDlgItemText(hwndRebindDlg, IDC_REBINDTEXTB, lpBuffer);

			free (lpBuffer);
			return DefWindowProc(hwndRebindDlg, imsg, wParam, lParam);
			
		default:
			return FALSE;
    }/*switch*/
return FALSE;
}/*end*/


/*
 * WM_CREATE Message Handler Function
 */
BOOL Lister_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
	unsigned int RC;


	if ((bIsNT) && (bSansCmdLine))
	{
		RC = CheckNTBindStatus ();

		switch (RC)
		{
			case 1: //no "PGPnetNTSafeToRebind" key exists
				DialogBox(g_hInstance, MAKEINTRESOURCE (IDD_REBINDDIALOG), hwnd, (DLGPROC) RebindDlgProc);
				exit(0);

			case 2: //"PGPnetNeedsReboot
				RebootYesNo ();
				exit(0);

			case 3: //Good to go ...
				break;
			
			default:
				MessageBox (GetFocus(), "Error checking bind status. You need to reinstall product.",
							TITLE, 0 | MB_ICONERROR);
				exit(0);
				break;
		}/*switch*/
	}/*if*/

	DialogBox(lpCreateStruct->hInstance, MAKEINTRESOURCE (IDD_LISTERDLG), hwnd, (DLGPROC) ListerDlgProc);
	FORWARD_WM_CREATE(hwnd, lpCreateStruct, DefWindowProc);
	return TRUE;
}/*end*/


/*
 * WM_DESTROY Message Handler Function
 */
void Lister_OnDestroy(HWND hwnd)
{
	PostQuitMessage(0);
	return;
}/*end*/


/*
 * ListerInitDialog Message Handler Function
 */
BOOL Lister_InitDialog(HWND hwndDlg, HWND hwnd, LPARAM lParam)
{
	//common
	HKEY			hMainKey	= HKEY_LOCAL_MACHINE;
	HKEY			hNewKey		= NULL;
	HKEY			hkey		= NULL;
	HKEY			phkResult	= NULL;
	LONG			lResult		= ERROR_SUCCESS;
	LPBYTE			pValue		= NULL;
	LPSTR			pszText		= NULL;
	DWORD			dwType;
	DWORD			dwSize;
	UINT			i;
	UINT			nCount;
	BOOL			brc;
	//List view
	LV_ITEM			lviKey;
	HWND			hListControl;
	HWND			hOkButton;


	i = 0;
	//Create the list view
	hListControl = GetDlgItem(hwndDlg, IDC_ADAPTERLIST);
	
	//Create the image list
	brc = CreateImageList();
	if (brc != TRUE)
		MessageBox (GetFocus(), ERR_IMGLISTCREATE, "", 0 | MB_ICONERROR);

	ListView_SetImageList(hListControl, g_hImages, LVSIL_SMALL);
	
	lviKey.mask     = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE ;
	lviKey.iItem    = 0;
	lviKey.iSubItem = 0;
	lviKey.iImage   = 2;
	
	nCount = 0;

	if (bIsNT)
	{
		//Running NT
		lResult = RegOpenKeyEx(hMainKey, TCPIP_SERVICES_KEY, 0, KEY_READ, &hNewKey);
		if (lResult != ERROR_SUCCESS)
		{
			MessageBox (GetFocus(), ERR_OPENREG, "", 0 | MB_ICONERROR);
			return FALSE;
		}/*if*/

		dwSize = 1024;
		pValue = (LPBYTE) calloc(sizeof(BYTE), dwSize);

		lResult = RegQueryValueEx(hNewKey, BINDINGS, 0, &dwType, pValue, &dwSize);
		if (lResult != ERROR_SUCCESS)
		{
			MessageBox (GetFocus(), ERR_READREG, "", 0 | MB_ICONERROR);
			RegCloseKey(hNewKey);
			free(pValue);
			return FALSE;
		}/*if*/

		while (i<dwSize)
		{	
			pszText			= GetTxtAfterLastSlash ((char *) &(pValue[i]));
			lviKey.pszText  = ResolveRealName (pszText);
			
			if ((lviKey.pszText != NULL) && 
				(strstr(lviKey.pszText, "PGPnet") == NULL))
			{
				nCount++;
				ListView_InsertItem(hListControl, &lviKey);
			}

			i += strlen((char *) &(pValue[i])) + 2;
			free(lviKey.pszText);
			free(pszText);
		}/*while*/
		free(pValue);
		RegCloseKey(hNewKey);
	}/*if*/
	else
	{
		//Running 95 or 98
		HKEY			hNewKeyb		= NULL;
		HKEY			hDeviceDesc		= NULL;
		HKEY			hPGPnetkey		= NULL;
		RegSearchState state;
		char			szSubKey[256];
		char			*szName;
		char			*szValue;
		LPTSTR 			pSubkeyBuffer	= NULL;	
		LPBYTE			pData			= NULL;
		DWORD			dwDisposition;
		unsigned long	lpcbMaxValueLen;


		state.hKey = HKEY_LOCAL_MACHINE;
		state.nextState = NULL;
		state.dwKeyIndex = 0;
		state.dwValueIndex = 0;
		state.bMatch = FALSE;
		
		szName = "Class";
		szValue = "Net";
		strcpy(szSubKey, "Enum");

		nCount = 0;
		if (RegOpenKeyEx(state.hKey, "Enum", 0, KEY_READ, &(state.hKey))
			== ERROR_SUCCESS)
		{
			while (RegistrySearch(szName, szValue, szSubKey, &state))
			{
				//Check to see if adapter is bound to TCPIP
				if (AmIBoundToTcpip95 (szSubKey))
				{
					//create the adapter reg inside the PGPnet key
					RegCreateKeyEx(HKEY_LOCAL_MACHINE, PATHTOADAPTERLIST,
					0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hPGPnetkey,
					&dwDisposition);
					
					//Get the DeviceDesc from the Reg. key and
					//Insert the item into List control
					RegOpenKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_READ, &hNewKeyb);
					RegQueryInfoKey (hNewKeyb, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
									NULL, &lpcbMaxValueLen, NULL, NULL);
					pData = malloc(lpcbMaxValueLen + 1);
					lResult = RegQueryValueEx(hNewKeyb, "DeviceDesc", 0,
											  &dwType, pData, &lpcbMaxValueLen);

					//Write the adapter entry under PGPnetkey (REALNAME -> REG KEY)
					RegSetValueEx(hPGPnetkey, pData , 0, REG_SZ, szSubKey,(strlen (szSubKey)+1));

					if (strstr(pData, "PGPnet") == NULL)
					{
						lviKey.pszText  = pData;
						lviKey.iItem	= nCount;
						ListView_Arrange(hListControl, LVA_ALIGNLEFT);
						ListView_InsertItem(hListControl, &lviKey);
						nCount++;
					}/*if*/
					

⌨️ 快捷键说明

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