Ejemplo n.º 1
0
int Dial(const char * szEntryName)
{
    LPRASDIALPARAMS lpRasDialParams = NULL;   // Structure to store the RasDial parameters
    HRASCONN        hRasConn = NULL;          // Handle to RAS connection
    DWORD           nRet = 0;                 // Return value from a function
    BOOL			bPassword;
    // Initialize the RASDIALPARAMS structure
    lpRasDialParams = (LPRASDIALPARAMS) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RASDIALPARAMS));
    if (NULL == lpRasDialParams)
    {
        printf("HeapAlloc failed\r\n");
        return -1;
    }
    gszLogData[0] = 0;
    strcpy_s(lpRasDialParams->szEntryName, szEntryName);
    lpRasDialParams->dwSize =sizeof(RASDIALPARAMS);
    RasGetEntryDialParams(NULL, lpRasDialParams, &bPassword);
    nRet = RasDial(NULL, NULL, lpRasDialParams, 0, &RasDialFunc, &hRasConn);
    return nRet;
}
Ejemplo n.º 2
0
//
// RasCustomDialDlg
//
// This export is the custom dial entry when RasDialDlg has been called by
// an application - the call is forwarded to here and it is up to this
// function then to display, handle and dial the phonebook entry that is
// specified
//
extern "C" BOOL WINAPI  RasCustomDialDlg (
  HINSTANCE hInstDll,      // handle to DLL instance
  DWORD dwFlags,           // reserved
  LPTSTR lpszPhonebook,    // pointer to the full path and 
                           //  file name of the phone-book file
  LPTSTR lpszEntry,        // pointer to the name of the 
                           //  phone-book entry to dial
  LPTSTR lpszPhoneNumber,  // pointer to replacement phone 
                           //  number to dial
  LPRASDIALDLG lpInfo,     // pointer to a structure that 
                           //  contains additional parameters
  PVOID pvInfo
)
{  
    DWORD rc = 0;               // return code
    HRASCONN hRasConn = NULL;
    DWORD dwSize = 0;
    PSAMPLE_CUSTOM_DIAL_DLG pDialData = NULL;
    RASDIALPARAMS RasDialParams;

    OutputTraceString(L"RasCustomDialDlg called in customdial.dll\n");

    if (!lpInfo)
    {
        return FALSE;
    }

    // set up the RasDialParams structure with information passed in
    ZeroMemory(&RasDialParams, sizeof(RASDIALPARAMS));
    RasDialParams.dwSize = sizeof(RASDIALPARAMS);
    StringCchCopy(RasDialParams.szEntryName, CELEMS(RasDialParams.szEntryName), lpszEntry);
    
    if (lpszPhoneNumber != NULL)
    {
        StringCchCopy(RasDialParams.szPhoneNumber, CELEMS(RasDialParams.szPhoneNumber), lpszPhoneNumber);
    }

    // pull information from the Entry for the dialog
    if (lpszEntry != NULL)
    {
        BOOL bPassword;

        if (rc = RasGetEntryDialParams(lpszPhonebook, &RasDialParams, &bPassword) != SUCCESS)
        {
            OutputTraceString(L"--- Error retrieving Entry Dial Parameters: %d\n", rc);
        }
        else
        {
            OutputTraceString(L"--- RasGetEntryDialParams: UN: '%s' D: '%s'\n", 
                              RasDialParams.szUserName,
                              RasDialParams.szDomain);
        }
    }
  
    // display dialog - passing in structure of data that the dialog needs
    // so we can get the username, password and domain information

    // first build the buffer of data to pass
    dwSize = sizeof(SAMPLE_CUSTOM_DIAL_DLG);
    pDialData = (PSAMPLE_CUSTOM_DIAL_DLG) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
    if (pDialData != NULL)
    {
        CopyMemory(&(pDialData->tDialParams), &RasDialParams, sizeof(pDialData->tDialParams));
        CopyMemory(&(pDialData->tDialDlg), lpInfo, sizeof(pDialData->tDialDlg));
      
        INT_PTR ret = DialogBoxParam(hInstDll, MAKEINTRESOURCE(IDD_CUSTOMDIALDLG), lpInfo->hwndOwner, CustomDialDlgProc, (LPARAM) pDialData);
        if (ret > 0)   // dialog succeeded
        { 
            // copy the results back of dialog entry back into stack variable
            CopyMemory(&RasDialParams, &(pDialData->tDialParams), sizeof(RASDIALPARAMS));

            // call the RasCustomDial since we just need it to do the same thing anyway but 
            // one would probably call their own custom dialer here or forward to RasDial using
            // another window for connection status.
            rc = RasCustomDial(hInstDll, NULL, lpszPhonebook, &RasDialParams, 0, 0, &hRasConn);    
   
            if (rc != 0)
            {
                // hang-up on error
                RasCustomHangUp(hRasConn);
                lpInfo->dwError = rc;
                rc = 0;     // return 0 on failure and set error info
            }
            else
            {
                // set the Entry Dial Params since we succeeded the dial
                if (rc = RasSetEntryDialParams(lpszPhonebook, &RasDialParams, TRUE) != SUCCESS)
                {
                    OutputTraceString(L"--- Error setting Entry Dial Parameters: %d\n", rc);
                }

                rc = 1;     // return >0 on success for the entire call
            }
        }
        else
        {
            lpInfo->dwError = GetLastError();
            OutputTraceString(L"--- DialogBox Failed (or cancelled) in RasCustomDialDlg (GetLastError = %d)\n", lpInfo->dwError);      
            rc = 0;
        }

        // Clear out password from memory
        ZeroMemory(&(pDialData->tDialParams.szPassword), sizeof(pDialData->tDialParams.szPassword));

        HeapFree(GetProcessHeap(), 0, (LPVOID)pDialData);
        pDialData = NULL;
    }
    else
    {
        OutputTraceString(L"--- Memory allocation failed (HeapAlloc) in RasCustomDialDlg (GetLastError = %d)\n", GetLastError());
        rc = ERROR_OUTOFMEMORY;
    }
  
    // Clear out structures in order to clear up the password from memory
    ZeroMemory(&RasDialParams, sizeof(RASDIALPARAMS));

    OutputTraceString(L"RasCustomDialDlg exiting customdial.dll with return code: %d\n", rc);

    return rc;
}