Results 1 to 5 of 5

Thread: Using RasEnumConnections

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    83

    Using RasEnumConnections

    Could someone please assist me with this code, I have tried to create this from the help file and even though it compliles correctly, the RasEnumConnections API call will not return the correct results. My code is as follows.

    {
    int ReturnCode =0;
    unsigned long *lpcb =0, *lpcConnections =0;
    unsigned long *my_hRasConn =0;
    RASCONN *lpRasConn[255];

    lpRasConn[0]->dwSize = sizeof(RASCONN);

    ReturnCode = RasEnumConnections(lpRasConn[0], lpcb, lpcConnections);

    if(ReturnCode == ERROR_SUCCESS)
    {
    RasHangUp(lpRasConn);
    }
    my_hRasConn = my_hRasConn;
    }

    Thankyou

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    MSDN: (does nobody EVER take a look at it?)
    Return Values
    If the function succeeds, the return value is zero.

    If the function fails, the return value is a nonzero error value listed in the RAS header file or one of ERROR_BUFFER_TOO_SMALL or ERROR_NOT_ENOUGH_MEMORY.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    try this

    PHP Code:
        LPRASENTRYNAME    lpRasEntryName;
        
    //
        
    DWORD            cEntries=0;
        
    DWORD            cb=0;
        
    //
        
    long            idx=0;

        
    // Create new RASENTRYNAME structure
        
    lpRasEntryName = (LPRASENTRYNAME)GlobalAlloc(GPTRsizeof(RASENTRYNAME));

        
    // Initialize the RASENTRYNAME structure
        
    lpRasEntryName->dwSize sizeof(RASENTRYNAME);
        
    // Get the entry name from registry
        
    idx RasEnumEntries(NULLNULLlpRasEntryName, &cb, &cEntries);
        
    // Out of memory + relocate the RASENTRYNAME structure size
        
    if (idx == ERROR_BUFFER_TOO_SMALL)
        {
            
    lpRasEntryName = (LPRASENTRYNAME)GlobalAlloc(GPTRcb);
            
    lpRasEntryName->dwSize sizeof(RASENTRYNAME);
        }
     
        
    // Calling RasEnumEntries to enumerate the phone-book entries    
        
    idx RasEnumEntries(NULLNULLlpRasEntryName, &cb, &cEntries);
        
    // Error checking
        
    if (idx != ERROR_SUCCESS)
        {
            
    // Notify user about the failure.
            
    MessageBox(hWndTEXT("Fail to load the RasDial entry from registry!"), TEXT("MyRasDial Error"), MB_OK MB_ICONEXCLAMATION);
            
    // Set the return value
            
    return 0;
        }
        else
        {
            
    // Loop through the return RASENTRYNAME structure
            
    for(idx=0idx < (long)cEntriesidx++)
            {
                
    // Add the ras entry into the comboboz control
                
    SendDlgItemMessage(hWndIDC_COMBO1CB_INSERTSTRING, -1, (LPARAM)lpRasEntryName->szEntryName);
                
    lpRasEntryName++;
            }
        }
        
    // Set the return value
        
    return (long)cEntries

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    GlobalAlloc is only kept for compatibility with 16-bit windows. You should use HeapAlloc instead.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    I'll try out with HeapAlloc later

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width