vc++ MFC 进行activex 控件的开发步骤就不用多写了,只是简单的说明一下方法,以及具体的代码:
使用的类库是 windows 系统的 rasapi32.dll
记住需要添加的头文件如下:
#include <Windows.h>
#include <Ras.h>
#include <RasError.h>
#pragma comment(lib, "rasapi32.lib")
代码如下:
VARIANT_BOOL CsecurityControlCtrl::VPNApp(void) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // TODO: 在此添加调度处理程序代码 DWORD dwCb = 0; DWORD dwRet = ERROR_SUCCESS; DWORD dwConnections = 0; LPRASCONN lpRasConn = NULL; // Call RasEnumConnections with lpRasConn = NULL. dwCb is returned with the required buffer size and // a return code of ERROR_BUFFER_TOO_SMALL dwRet = RasEnumConnectionsW(lpRasConn, &dwCb, &dwConnections); if (dwRet == ERROR_BUFFER_TOO_SMALL){ // Allocate the memory needed for the array of RAS structure(s). lpRasConn = (LPRASCONN) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCb); if (lpRasConn == NULL){ return false; } // The first RASCONN structure in the array must contain the RASCONN structure size lpRasConn[0].dwSize = sizeof(RASCONN); // Call RasEnumConnections to enumerate active connections dwRet = RasEnumConnectionsW(lpRasConn, &dwCb, &dwConnections); // If successful, print the names of the active connections. if (ERROR_SUCCESS == dwRet){ if(dwConnections>0) { return true; } else { return false; } } //Deallocate memory for the connection buffer HeapFree(GetProcessHeap(), 0, lpRasConn); lpRasConn = NULL; } return false; }
时间: 2024-11-13 15:12:03