PPP拨号上网协议 有偿寻求技术支持

weixin_41144658 2019-07-20 07:18:37
PPP拨号上网协议 有偿寻求技术支持

完整PPP拨号上网Delphi版源代码,其中包括LCP,PAP,CHAP,NCP等完整对话协议。通过PPP拨号上网后能过正常访问网络。有偿寻求技术支持。也可以使用其它语言封装成DLL提供接口调用(DLL文件需提供源代码和编译环境设置)
...全文
193 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sczyq 2019-08-09
  • 打赏
  • 举报
回复
这些是我以前XP下做过, Win7 不知道行不行, 都是BCB的代码, 可以参考下: DeviceControls.h
//---------------------------------------------------------------------------
#ifndef DeviceControlsH
#define DeviceControlsH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <SetupAPI.h>
//---------------------------------------------------------------------------
#define DN_DISABLEABLE              (0x00002000)   // Can be rebalanced
#define DN_HAS_PROBLEM              (0x00000400)   // Need device installer
#define CM_PROB_DISABLED            (0x00000016)   // devinst is disabled
#define CM_PROB_HARDWARE_DISABLED   (0x0000001D)   // device disabled
//---------------------------------------------------------------------------
enum TGetDeviceState { gdsError, gdsEnabled, gdsDisabled };
typedef void __fastcall (__closure * TDeviceCallback)(DWORD, String, bool);
//---------------------------------------------------------------------------
class TDeviceControl : public TComponent
{
private:
	HINSTANCE FInstance;
	int (__stdcall *FCallProgram)(PULONG, PULONG, ULONG, ULONG);
	bool __fastcall GetRegistryProperty(HDEVINFO DeviceInfoSet,
				 PSP_DEVINFO_DATA DeviceInfoData, ULONG Property,
				 PVOID Buffer, PULONG Length);
	TGetDeviceState __fastcall GetDeviceInstState(ULONG DeviceInst);
	bool __fastcall IsCannotDisable(ULONG DeviceInst);
public:
	void __fastcall EnumDevices(String AProperty, TDeviceCallback ACallback);
	bool __fastcall SetDeviceState(DWord ADevice, bool AEnabled);
	bool __fastcall GetDeviceState(DWord ADevice);
	int __fastcall OSVersion(void);
	__fastcall TDeviceControl(TComponent * AOwner);
	__fastcall ~TDeviceControl(void);
};
//---------------------------------------------------------------------------
#endif
DeviceControls.cpp
//---------------------------------------------------------------------------
#pragma hdrstop
#include "DeviceControls.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall TDeviceControl::TDeviceControl(TComponent * AOwner) : TComponent(AOwner)
{
	FInstance = LoadLibrary("SetupAPI.DLL");
	if (FInstance)
		(FARPROC) FCallProgram
				= GetProcAddress(FInstance,"CM_Get_DevNode_Status");
	else FCallProgram = NULL;
}
//---------------------------------------------------------------------------
__fastcall TDeviceControl::~TDeviceControl(void)
{
	if (FInstance)
		FreeLibrary(FInstance);
}
//---------------------------------------------------------------------------
bool __fastcall TDeviceControl::GetRegistryProperty(HDEVINFO DeviceInfoSet,
			 PSP_DEVINFO_DATA DeviceInfoData,
			 ULONG Property, PVOID Buffer, PULONG Length)
{
	while (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
		DeviceInfoData, Property, NULL, (BYTE *)*(TCHAR **)Buffer, *Length, Length))
	{
		if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
		{
			if (*(LPTSTR *)Buffer) LocalFree(*(LPTSTR *)Buffer);
			*(LPTSTR *)Buffer = (PCHAR)LocalAlloc(LPTR,*Length);
		}
		else return false;
	}
	return (*(LPTSTR *)Buffer)[0];
}
//---------------------------------------------------------------------------
TGetDeviceState __fastcall TDeviceControl::GetDeviceInstState(ULONG DeviceInst)
{
	DWORD Status, Problem;
	ULONG dtFlag = 0;

	if (FCallProgram(&Status, &Problem, DeviceInst,dtFlag) != 0)
		return gdsError;

	if ((Status & DN_HAS_PROBLEM) && (CM_PROB_DISABLED == Problem))
		return gdsDisabled;
    else return gdsEnabled;
}
//---------------------------------------------------------------------------
bool __fastcall TDeviceControl::IsCannotDisable(ULONG DeviceInst)
{
	DWORD Status, Problem;
	ULONG dtFlag = 0;

	if (FCallProgram(&Status, &Problem, DeviceInst, dtFlag) != 0)
		return true;

	return !((Status & DN_DISABLEABLE) && (CM_PROB_HARDWARE_DISABLED != Problem));
}
//---------------------------------------------------------------------------
void __fastcall TDeviceControl::EnumDevices(String AProperty, TDeviceCallback ACallback)
{
	LPTSTR Buffer = NULL;
	DWORD BufSize = 0;
	HDEVINFO hDevInfo;

	if (INVALID_HANDLE_VALUE == (hDevInfo =
				SetupDiGetClassDevs(NULL,NULL,0,DIGCF_PRESENT|DIGCF_ALLCLASSES)))
		return;

	SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};

	for (DWORD Id = 0; SetupDiEnumDeviceInfo(hDevInfo, Id, &DeviceInfoData); Id++)
	if (GetRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_CLASS , &Buffer, (PULONG)&BufSize))
	if (SameText(Buffer, AProperty))
	if (GetRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_ENUMERATOR_NAME , &Buffer, (PULONG)&BufSize))
	if (!SameText(Buffer, "ROOT"))
	{
		String ACaption = "<Unknown Device>";
		if (GetRegistryProperty(hDevInfo, &DeviceInfoData,
					SPDRP_DEVICEDESC , &Buffer, (PULONG)&BufSize))
			ACaption = Buffer;
		bool AEnabled = GetDeviceInstState(DeviceInfoData.DevInst) == gdsEnabled;
		ACallback(Id, ACaption, AEnabled);
	}
	if (*(LPTSTR *)Buffer) LocalFree(*(LPTSTR *)Buffer);
}
//---------------------------------------------------------------------------
bool __fastcall TDeviceControl::SetDeviceState(DWORD ADevice, bool AEnabled)
{
	HDEVINFO hDevInfo;

	if (INVALID_HANDLE_VALUE == (hDevInfo =
				SetupDiGetClassDevs(NULL,NULL,0,DIGCF_PRESENT|DIGCF_ALLCLASSES)))
		return false;

	SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};

	if (!SetupDiEnumDeviceInfo(hDevInfo,ADevice,&DeviceInfoData))
        return false;

	TGetDeviceState IsEnabled = GetDeviceInstState(DeviceInfoData.DevInst);

	if (IsEnabled == gdsError) return false;

    SP_PROPCHANGE_PARAMS PropChangeParams = {sizeof(SP_CLASSINSTALL_HEADER)};
	PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
	PropChangeParams.Scope = DICS_FLAG_GLOBAL;

	if (AEnabled)
    {
		if (IsEnabled == gdsEnabled)
			return false;

		PropChangeParams.StateChange = DICS_ENABLE;
	}
	else
	{
		if (IsEnabled == gdsDisabled)
			return false;

		if (IsCannotDisable(DeviceInfoData.DevInst))
			return false;

		PropChangeParams.StateChange = DICS_DISABLE;
	}

	if (SetupDiSetClassInstallParams(hDevInfo, &DeviceInfoData,
		(SP_CLASSINSTALL_HEADER *)&PropChangeParams, sizeof(PropChangeParams)))
	if (SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, &DeviceInfoData))
	{
		IsEnabled = GetDeviceInstState(DeviceInfoData.DevInst);
		if (IsEnabled == AEnabled ? gdsEnabled : gdsDisabled)
			return true;
	}
	return false;
}
//---------------------------------------------------------------------------
bool __fastcall TDeviceControl::GetDeviceState(DWord ADevice)
{
	HDEVINFO hDevInfo;
	if (INVALID_HANDLE_VALUE == (hDevInfo =
                SetupDiGetClassDevs(NULL,NULL,0,DIGCF_PRESENT|DIGCF_ALLCLASSES)))
		return gdsError;
	SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};
	if (!SetupDiEnumDeviceInfo(hDevInfo,ADevice, &DeviceInfoData))
        return gdsError;

	TGetDeviceState IsEnabled = GetDeviceInstState(DeviceInfoData.DevInst);

	return IsEnabled == gdsEnabled;
}
//---------------------------------------------------------------------------
int __fastcall TDeviceControl::OSVersion(void)
{
    OSVERSIONINFO OSVI;
    OSVI.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx( &OSVI );
    return OSVI.dwMajorVersion;
}
//---------------------------------------------------------------------------
jefflin070 2019-08-08
  • 打赏
  • 举报
回复
只能帮顶 早日
qq511388601 2019-07-30
  • 打赏
  • 举报
回复
只能帮顶 早日

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧