代码更正,以使RASENUM连接在XP中工作 [英] code correction to make RASENUM connections to work in XP

查看:70
本文介绍了代码更正,以使RASENUM连接在XP中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://msdn.microsoft .com/en-us/library/windows/desktop/aa377284(v = vs.85).aspx [
我在调用RasEnumConnections之前添加了以下两行,并且工作正常.这样对吗?如果我错了,请纠正我.

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);


以下是我的代码,来自microcsoft,上面添加了两行.


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;

    // Call RasEnumConnections with lpRasConn = NULL. dwCb is returned with the required buffer size and 
    // a return code of ERROR_BUFFER_TOO_SMALL
    /*I ADDED THE BELOW TWO LINES */

    lpRasConn = (LPRASCONN) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCb);
    lpRasConn[0].dwSize = sizeof(RASCONN);

    dwRet = RasEnumConnections(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){
            wprintf(L"HeapAlloc failed!\n");
            return 0;
        }
        // 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 = RasEnumConnections(lpRasConn, &dwCb, &dwConnections);

        // If successful, print the names of the active connections.
        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);
                  }
        }
        //Deallocate memory for the connection buffer
        HeapFree(GetProcessHeap(), 0, lpRasConn);
        lpRasConn = NULL;
        return 0;
    }

    // There was either a problem with RAS or there are no connections to enumerate    
    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;
}

推荐答案

会使其错误"的事情是....

1.它不起作用.
2.引发异常.
3.如果您重复调用此方法,它将失败.
4.泄漏资源.
The things that would make it ''wrong'' are....

1. It doesn''t work.
2. It throws exceptions.
3. It fails if you make repeated calls to this method.
4. It leaks resources.


这篇关于代码更正,以使RASENUM连接在XP中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆