As commented on
http://msdn.microsoft.com/en-us/library/windows/desktop/aa377284(v=vs.85).aspx[
^] this link RasEnum code I face the same problem:
Possible inaccuracy in the Note section to lpcb param. Calling RasEnumConnections with lprasconn set to NULL to determine the required buffer size, it doesn't seem to work on Window ver < Vista.
I added the below two lines before calling the RasEnumConnections, and it works fine. Is it right? Please correct me if I am wrong.
lpRasConn = (LPRASCONN) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCb); lpRasConn[0].dwSize = sizeof(RASCONN);
The below is my code, from microcsoft added with above two lines.
#include <windows.h>
#include <stdio.h>
#include "ras.h"
#include "raserror.h"
#pragma comment(lib, "rasapi32.lib")
DWORD __cdecl wmain(){
DWORD dwCb = 0;
DWORD dwRet = ERROR_SUCCESS;
DWORD dwConnections = 0;
LPRASCONN lpRasConn = NULL;
lpRasConn = (LPRASCONN) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCb);
lpRasConn[0].dwSize = sizeof(RASCONN);
dwRet = RasEnumConnections(lpRasConn, &dwCb, &dwConnections);
if (dwRet == ERROR_BUFFER_TOO_SMALL){
lpRasConn = (LPRASCONN) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCb);
if (lpRasConn == NULL){
wprintf(L"HeapAlloc failed!\n");
return 0;
}
lpRasConn[0].dwSize = sizeof(RASCONN);
dwRet = RasEnumConnections(lpRasConn, &dwCb, &dwConnections);
if (ERROR_SUCCESS == dwRet){
wprintf(L"The following RAS connections are currently active:\n");
for (DWORD i = 0; i < dwConnections; i++){
wprintf(L"%s\n", lpRasConn[i].szEntryName);
}
}
HeapFree(GetProcessHeap(), 0, lpRasConn);
lpRasConn = NULL;
return 0;
}
if(dwConnections >= 1){
wprintf(L"The operation failed to acquire the buffer size.\n");
}else{
wprintf(L"There are no active RAS connections.\n");
}
return 0;
}