判断有无拨号连接:
#include <windows.h>
#include <stdio.h>
#include <ras.h>
#include <raserror.h>int main()
{
    DWORD dwCb = sizeof(RASCONN);
    DWORD dwErr = ERROR_SUCCESS;
    DWORD dwRetries = 5;
    DWORD dwConnections = 0;
    RASCONN* lpRasConn = NULL;    //
    // Loop through in case the information from RAS changes between calls.
    //
    while (dwRetries--)
    {
        //
        // If the memory is allocated, free it.
        //
        if (NULL != lpRasConn)
        {
            HeapFree(GetProcessHeap(), 0, lpRasConn);
            lpRasConn = NULL;
        }
        //
        // Allocate the size needed for the RAS structure.
        //
        lpRasConn = (LPRASCONN) HeapAlloc(GetProcessHeap(), 0, dwCb);
        if (NULL == lpRasConn)
        {
            dwErr = ERROR_NOT_ENOUGH_MEMORY;
            break;
        }
ZeroMemory(lpRasConn, sizeof(RASCONN));
        //
        // Set the structure size for version checking purposes.
        //
        lpRasConn->dwSize = sizeof(RASCONN);
        //
        // Call the RAS API then exit the loop if we are successful or an unknown
        // error occurs.
        //
    dwErr = RasEnumConnections(
                    lpRasConn,
                    &dwCb,
                    &dwConnections);
        if (ERROR_BUFFER_TOO_SMALL != dwErr)
        {
            break;
        }
    }
    //
    // In the success case, print the names of the connections.
    //
    if (ERROR_SUCCESS == dwErr)
    {
        DWORD i;        printf("The following RAS connections are currently active\n\n");
        for (i = 0; i < dwConnections; i++)
        {
            printf("%s\n", lpRasConn[i].szEntryName);
        }
    }
    else
    {
        printf("RasEnumConnections failed: Error = %d\n", dwErr);
    }
    //
    // Free the memory if necessary.
    //
    if (NULL != lpRasConn)
    {
        HeapFree(GetProcessHeap(), 0, lpRasConn);
        lpRasConn = NULL;
    }}编译通过,但执行时rasenumconnections返回错误码632——ERROR_INVALID_SIZE。
以上代码是MSDN上面的。看到别人相同的问题有网友提示
1、重启拨号器
——怎样重启拨号器。
2、,#define WINVER >0x500
——还是不行

解决方案 »

  1.   

    如果当前是2000系统,定义为0x500,如果为XP系统,定义为0x600,另外注意VC是使用老的ras.h,你必须把最新platform sdk的ras.h放到最前。
      

  2.   

    to:kingzai(kingzai) 多谢多谢!多谢回答我的问题。
    1、在2000下我定义了 0x501
    #define WINVER 0x501
    #include "stdafx.h"
    #include "windows.h"
    #include "stdio.h"
    #include "Ras.h"
    #include "raserror.h"可还是不行。2、我用的是sdk中的ras.h,是在最前,日期是2003/03应该是最新的了。
    还是不行。请继续指教。
      

  3.   

    你肯定是把sdk中的ras.h放在最前了,把vc中的放在最前在2000/XP下都没有问题。至于原因,我也没有弄明白,望知者明示。