Newsgroup: it.comp.lang.c++
Titolo: Microsoft RAS Library

Qualcuno sa come si fa a creare una nuova Dial Up Entry con la Microsoft RAS
Library ?
La funzione RasCreatePhonebookEntry() apre una dialog interattiva per chiedere
dei parametri che invece vorrei impostare come parametri alla funzione;
Greetings, Alessandro
http://www.esalab.it
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/
       Search, Read, Discuss, or Start Your Own    

...

Copia e incolla di un pezzo di codice che scrissi.
Mancano le definizioni delle variabili e gli header
   // First of all we must check for the presence o our
   // RasDialEntry in the Registry
   ArrayRasEntryName[0].dwSize=sizeof(RASENTRYNAME);
   BuffSize=sizeof(ArrayRasEntryName);
   if (0==RasEnumEntries(NULL,NULL,
    &(ArrayRasEntryName[0]),&BuffSize,&nWritten)){
    NotPresent=TRUE;
    for
nWritten;i++){     
     if (0==lstrcmp(ArrayRasEntryName[i].szEntryName,ENTRY_NAME)){
      NotPresent=FALSE;
      RasDialParams.dwSize=sizeof(RASDIALPARAMS);
      lstrcpy(RasDialParams.szEntryName,ENTRY_NAME);
      RasDialParams.szPhoneNumber[0]=0;
      RasDialParams.szCallbackNumber[0]=0;
      RasGetEntryDialParams(NULL,&RasDialParams,&nBool);
     };
    };
    // it is necessary to create RasDialEntry
    if (NotPresent){
    RasEnumEntries(NULL,NULL,NULL,&BuffSize,NULL);
    BuffSize=sizeof(RASENTRY);
    RasEntry.dwSize=sizeof(RASENTRY);
    if (0==RasGetEntryProperties(NULL,   // does not use PhoneBook
                                 L"",    // dont specify name, so let create
                                 (BYTE *)&RasEntry,&BuffSize,
                                 NULL,NULL)){
     lstrcpy(RasEntry.szDeviceName,L"Serial Cable on COM2:");
     BuffSize=sizeof(RASENTRY);
     if (0==RasSetEntryProperties(NULL,
             L"Profibus7_CONN",
             (BYTE *)&RasEntry,BuffSize,NULL,0)){
      RasDialParams.dwSize=sizeof(RASDIALPARAMS)
;
      lstrcpy(RasDialParams.szEntryName,ENTRY_NAME);
      RasDialParams.szPhoneNumber[0]=0;
      RasDialParams.szCallbackNumber[0]=0;
      lstrcpy(RasDialParams.szUserName,L"Administrator");
      lstrcpy(RasDialParams.szPassword,L"");
      lstrcpy(RasDialParams.szDomain,L"");
      if (0==RasSetEntryDialParams(NULL,
              &RasDialParams,
              FALSE)){
       // here is successfull
      } else {
       MessageBox(hDlg,L"NO RasSetEntryDialParams",L"Info",MB_OK);
      };
     } else {
      MessageBox(hDlg,L"NO RasSetEntry",L"Info",MB_OK);
     };
    } else {
     MessageBox(hDlg,L"NO RasGetEntry",L"Info",MB_OK);
    };
    }; // end of if  (NotPresent)
    SetDlgItemText(hDlg,IDC_RASSTATE,L"Trying to RasDial");
    RasConn.hrasconn=NULL;
    if (0==RasDial(NULL,NULL,&RasDialParams,
                 0xFFFFFFFF,hDlg,&RasConn.hrasconn)){
      if (RasConn.hrasconn!=NULL) {
       SetDlgItemText(hDlg,IDC_RASSTATE,L"Habemus CONN");
      };
    } else {
     MessageBox(hDlg,L"NO RasDial",L"Info",MB_OK);
    };
   };

              (BYTE *)&RasEntry,BuffSize,NULL,0)){
La funzione non e' esportata nella dll e mi da' errore in esecuzione; qualche
suggerimento ?
il programma deve funzionare sotto win95 e win98


 suggerimento ?
Sembra che windows 95 prime versioni non l'avesse: comunque ora mi da'
l'errore Invalid RasNumEntries.
Spero di arrivare alla fine :(


l'errore Invalid RasNumEntries.
Ho rivisto il codice scritto in passato,  e ho testato il seguente frammento
sotto WinNT 4.0 SP3, IE 4.01, VC++6 SP1
#include <windows.h>
#include <ras.h>
#include <raserror.h>
#include <iostream>
using namespace std;
int main(int argc, char ** argv){
 DWORD BuffSize=0;
    RASENTRYNAME   RasEntryFoo;
 RASENTRYNAME * pRasEntryNames;
 RASENTRY     * pRasEntry;
 RASDIALPARAMS  RasDialParams;
 DWORD NumEntries=0;
 DWORD dwRet;
 RasEntryFoo.dwSize=sizeof(RASENTRYNAME);
 BuffSize=sizeof(RASENTRYNAME);
    dwRet=RasEnumEntries(NULL,NULL,&RasEntryFoo,&BuffSize,&NumEntries);
 if ((dwRet == ERROR_BUFFER_TOO_SMALL ) ||
  (dwRet == ERROR_NOT_ENOUGH_MEMORY)){
  pRasEntryNames=(RASENTRYNAME *)HeapAlloc(GetProcessHeap(),0,BuffSize);
  pRasEntryNames[0].dwSize=sizeof(RASENTRYNAME);
  dwRet=RasEnumEntries(NULL,NULL,pRasEntryNames,&BuffSize,&NumEntries);
  if (dwRet==0){
   for(int i=0;i<NumEntries;++i){
    cout<<" "<<i<<" "<<pRasEntryNames[i].szEntryName<<endl;
   };
  } else {
   cout<<"error RasEnumEntries Alloc"<<dwRet<<endl;
  }
  HeapFree(GetProcessHeap(),0,pRasEntryNames);
    } else {
  cout<<"error RasEnumEntries NULL"<<dwRet<<endl;
 };
 BuffSize=0;
    dwRet=RasGetEntryProperties(NULL,   // does not use PhoneBook
                                "",    // dont specify name, so let create
                                NULL, //&RasEntry,
        &BuffSize,
                                NULL,
        0);
 if ((dwRet == ERROR_BUFFER_TOO_SMALL ) ||
  (dwRet == ERROR_NOT_ENOUGH_MEMORY)){
  pRasEntry=(RASENTRY *)HeapAlloc(GetProcessHeap(),0,BuffSize);
  pRasEntry[0].dwSize=sizeof(RASENTRY);
  dwRet=RasGetEntryProperties(NULL,   // does not use PhoneBook
                                "",    // dont specify name, so let create
                                pRasEntry, //&RasEntry,
        &BuffSize,
                                NULL,
        0);
  if (dwRet==0){
   cout<<pRasEntry[0].szDeviceName<<endl;
   lstrcpy(pRasEntry[0].szDeviceName,"Rockwell HCF 56K Data Fax PCI Modem
(COM3)");
   if (0==RasSetEntryProperties(NULL,
                "Profibus7_CONN",
                                     pRasEntry,
                            BuffSize,
                            NULL,
                            0)){
    RasDialParams.dwSize=sizeof(RASDIALPARAMS);
    lstrcpy(RasDialParams.szEntryName,"Profibus7_CONN");
    RasDialParams.szPhoneNumber[0]=0;
    RasDialParams.szCallbackNumber[0]=0;
    lstrcpy(RasDialParams.szUserName,"Administrator");
    lstrcpy(RasDialParams.szPassword,"password");
    lstrcpy(RasDialParams.szDomain,"");
    if (0==RasSetEntryDialParams(NULL,
                          &RasDialParams,
                                         FALSE)){
    // here is successfull
    } else {
     MessageBox(NULL,"NO RasSetEntryDialParams","Info",MB_OK);
    };
   } else {
    MessageBox(NULL,"NO RasSetEntry","Info",MB_OK);
   };
  } else {
   cout<<"error RasGetEntryProperties Alloc "<<dwRet<<endl;
  }
  HeapFree(GetProcessHeap(),0,pRasEntry);
    } else {
  cout<<"NO RasGetEntryProperties "<<dwRet<<endl;
 };
 return 0;
}

  };
Greetings, Alessandro
