RasEnumAutodialAddressesA 函式 (ras.h)

RasEnumAutodialAddresses 函式會傳回 AutoDial 對應資料庫中所有地址的列表。

語法

DWORD RasEnumAutodialAddressesA(
  [in, out] LPSTR   *lppRasAutodialAddresses,
  [in, out] LPDWORD lpdwcbRasAutodialAddresses,
  [out]     LPDWORD lpdwcRasAutodialAddresses
);

參數

[in, out] lppRasAutodialAddresses

字串指標陣列的指標,在緩衝區結尾儲存字串本身的額外空間。

輸出時,每個字串都會接收自動串行對應資料庫中的位址名稱。

如果輸入上的 lppAddressesNULL,RasEnumAutodialAddresses 會設定 lpdwcbAddresses 和 lpdwcAddresses 參數,以指出所需的大小、以位元組為單位,以及資料庫中的地址項目數目。

[in, out] lpdwcbRasAutodialAddresses

輸入時,變數的指標包含 由 lpRasEnumAutodialAddressespAddressespAddresses 參數所指定的緩衝區大小,以位元組為單位。

注意  

若要判斷所需的緩衝區大小,請呼叫 RasEnumAutodialAddresses 並將 lppAddresses 設定為 NULLlpdwcbAddresses 指向的變數應該設定為零。 函式會傳回 lpdwcbAddresses 中所需的緩衝區大小,以及 ERROR_BUFFER_TOO_SMALL的錯誤碼。

 

[out] lpdwcRasAutodialAddresses

變數的指標,該變數會接收 lppAddresses 緩衝區中傳回的位址字串數目。

傳回值

如果函式成功,傳回值會 ERROR_SUCCESS

如果函式失敗,則傳回值是下列其中一個錯誤碼,或 來自路由和遠端訪問錯誤碼 或 Winerror.h 的值。

意義
ERROR_INVALID_PARAMETER
針對 lpdwcbAddresseslpdwcAddresses 參數傳遞 NULL。
ERROR_BUFFER_TOO_SMALL
lppAddresses 緩衝區為 NULL而 lpdwcbAddresses 為零。 函式會傳回 lpdwcbAddresses 所指向之變數中所需的緩衝區大小。

備註

下列程式代碼範例程式代碼會使用 RasEnumAutodialAddresses 列舉自動串行對應資料庫。

#include <windows.h>
#include <stdio.h>
#include "ras.h"
#include "raserror.h"
#include <tchar.h>

DWORD __cdecl wmain(){

    DWORD dwBytes = 0;
    DWORD dwRet = ERROR_SUCCESS;
    DWORD dwAddresses = 0;
    LPTSTR * lppAddresses = NULL;
    LPCTSTR lpEntryAddress = L"www.microsoft.com";

    // Allocate memory for a new Autodial address to add to the mapping database
    LPRASAUTODIALENTRY lpentry = (LPRASAUTODIALENTRY) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RASAUTODIALENTRY));
    lpentry->dwSize = sizeof(RASAUTODIALENTRY);

    // Add a (non-functional) address to the Autodial mapping database
    // (this ensures RasEnumAutodialAddresses() has something to return)
    dwRet = RasSetAutodialAddress(lpEntryAddress, 0, lpentry, lpentry->dwSize, 1);
    
    // Call RasEnumAutodialAddresses() with lppAddresses = NULL. dwBytes is returned with the 
    // required buffer size and a return code of ERROR_BUFFER_TOO_SMALL
    dwRet = RasEnumAutodialAddresses(lppAddresses, &dwBytes, &dwAddresses);

    if (dwRet == ERROR_BUFFER_TOO_SMALL){
        // Allocate the memory needed for the array of RAS Autodial addresses.
        lppAddresses = (LPTSTR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwBytes);
        if (lppAddresses == NULL){
            wprintf(L"HeapAlloc failed!\n");
            return 0;
        }
        
        // Call RasEnumAutodialAddresses() to enumerate all RAS Autodial addresses
        dwRet = RasEnumAutodialAddresses(lppAddresses, &dwBytes, &dwAddresses);

        // If successful, print the RAS Autodial addresses
        if (dwRet == ERROR_SUCCESS){
            wprintf(L"The following RAS Autodial addresses were found:\n");
            for (DWORD i = 0; i < dwAddresses; i++){
                wprintf(L"%s\n", lppAddresses[i]);
            }
        }
        // Remove the address
        dwRet = RasSetAutodialAddress(lpEntryAddress, 0, NULL, 0, 0);
        
        //Deallocate memory for the address buffers
        HeapFree(GetProcessHeap(), 0, lppAddresses);    
        HeapFree(GetProcessHeap(), 0, lpentry);
        lppAddresses = NULL;
        return 0;
    }

    // There was either a problem with RAS or there are no RAS Autodial addresses to enumerate
    if(dwAddresses >= 1){
        wprintf(L"The operation failed to acquire the buffer size.\n");
    }else{
        wprintf(L"There were no RAS Autodial addresses found.\n");
    }

    // Remove the address
    dwRet = RasSetAutodialAddress(lpEntryAddress, 0, NULL, 0, 0);
    HeapFree(GetProcessHeap(), 0, lpentry);
    return 0;
}

注意

ras.h 標頭會根據 UNICODE 預處理器常數的定義,將 RasEnumAutodialAddresses 定義為自動選取此函式的 ANSI 或 Unicode 版本。 混合使用編碼中性別名與非編碼中性的程序代碼,可能會導致編譯或運行時間錯誤不符。 如需詳細資訊,請參閱 函式原型的慣例

規格需求

需求
最低支援的用戶端 Windows 2000 Professional [僅限傳統型應用程式]
最低支援的伺服器 Windows 2000 Server [僅限桌面應用程式]
目標平台 Windows
標頭 ras.h
程式庫 Rasapi32.lib
Dll Rasapi32.dll

另請參閱

RASAUTODIALENTRY

RasGetAutodialAddress

RasSetAutodialAddress

遠端訪問服務 (RAS) 概觀

遠端存取服務函式