🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9351

Re: Ras again

#9351
From: Babak
Date: Sat, 17 Jul 2004 20:34
226 lines
7915 bytes
//--------------------------------------------------------------------------
-

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "wininet.h"
#define WINVER 0x400
#include "ras.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"

TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//--------------------------------------------------------------------------
-

void __fastcall TForm1::Button4Click(TObject *Sender)
{
  Close();
}
//--------------------------------------------------------------------------
-
//void __fastcall TfrmInfo::EnumNetRes(NETRESOURCE* nr);
void __fastcall EnumNetRes(NETRESOURCE* nr);
void __fastcall TForm1::EnumNetRes1Click(TObject *Sender)
{
    EnumNetRes(NULL);
}
//--------------------------------------------------------------------------
-
void __fastcall EnumNetRes(NETRESOURCE* nr)
{
  String NetStr = "Network Resources: "; HANDLE hEnum;
  //NetResource=NULL : we want to enumerate all resources

  if(
     WNetOpenEnum(
        RESOURCE_GLOBALNET,
        RESOURCETYPE_ANY,
        RESOURCEUSAGE_CONTAINER|RESOURCEUSAGE_CONNECTABLE,
        nr,&hEnum)!=NO_ERROR)
  {return;}

  DWORD Count=-1; DWORD BufferSize=0; DWORD ReturnVal=0;  //Enum all
resources

  NETRESOURCE *NetRes=(NETRESOURCE*)new char[1024];
  ZeroMemory(NetRes,sizeof(NETRESOURCE));
  for(;;)
  {
    ReturnVal=WNetEnumResource(hEnum,&Count,NetRes,&BufferSize);
    if(ReturnVal==ERROR_MORE_DATA)  //we set the size of NetRes
    {
      Count=-1; delete[] NetRes;  //we set the size of NetRes if there is
more data
      NetRes=(NETRESOURCE*)new char[BufferSize];
      ZeroMemory(NetRes,sizeof(NETRESOURCE));
      ReturnVal=WNetEnumResource(hEnum,&Count,NetRes,&BufferSize);
    }
    if(ReturnVal!=NO_ERROR)break;
    for (unsigned int i=0;i<Count;i++)
    {
      ShowMessage(NetStr + NetRes[i].lpRemoteName);
      Application->ProcessMessages();
      if((NetRes[i].dwUsage &
RESOURCEUSAGE_CONTAINER)==RESOURCEUSAGE_CONTAINER)
EnumNetRes(&NetRes[i]);
    }
    if(ReturnVal==ERROR_NO_MORE_ITEMS)
    {
      delete[] NetRes;
      WNetCloseEnum(hEnum);
    }
  }
  delete[] NetRes;
  WNetCloseEnum(hEnum);
}
void __fastcall TForm1::KingofPersianHackers1Click(TObject *Sender)
{
   ShowMessage("If you think you are not my slave \ntry to write more better
softwares than me :-D");
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Image1DblClick(TObject *Sender)
{
   AnsiString MyStr=InputBox("Cheat Box","Cheat :","Fuck the Fucking
Fuckers...");
   if(!strcmp("popup",MyStr.c_str())){
      Image1->Hide();
      Timer1->Enabled=true;
   }
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
   Image1->Show();
   Timer1->Enabled=false;
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
   PopupMenu->Popup(10,10);
}
//--------------------------------------------------------------------------
-
String __fastcall Get_OperatingSystemInfo(bool display_info);
void __fastcall TForm1::OperatingSystemInfo1Click(TObject *Sender)
{
   Get_OperatingSystemInfo(1);
}
//--------------------------------------------------------------------------
-
String __fastcall Get_OperatingSystemInfo(bool display_info)
{
   OSVERSIONINFO vInfo;
   ZeroMemory(&vInfo, sizeof(OSVERSIONINFO));
   vInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
   String S_os, S_majorv, S_minorv, S_build, OS_type;
   if (GetVersionEx(&vInfo)){
      S_os = "Microsoft Windows ";
      switch (vInfo.dwPlatformId){
         case VER_PLATFORM_WIN32s : S_os += "3.1"; OS_type = "3.1";  break;
         case VER_PLATFORM_WIN32_WINDOWS :
         if(vInfo.dwMajorVersion == 4 && vInfo.dwMinorVersion == 0){
            S_os += "95";
            if(vInfo.szCSDVersion[1] == 'C') {
               S_os += "OSR2";
               OS_type =  "OSR2";
               break;}
            }
            if(vInfo.dwMajorVersion == 4 && vInfo.dwMinorVersion == 10) {
               S_os +="98";
               if(vInfo.szCSDVersion[1] == 'A') {
                  S_os += "SE";
                  OS_type =  "SE";
                  break; }
               }
               if(vInfo.dwMajorVersion == 4 && vInfo.dwMinorVersion == 90) {
                  S_os +="ME";
                  OS_type =  "ME";
                  break;
               }
         case VER_PLATFORM_WIN32_NT :
         if(vInfo.dwMajorVersion == 3) {
            S_os += "NT 3.51";
            OS_type =  "NT 3.51";
            break;
         }
         if(vInfo.dwMajorVersion == 4) {
            S_os += "NT 4.0";
            OS_type =  "NT 4.0";
            break;
         }
         if(vInfo.dwMajorVersion == 5 && vInfo.dwMinorVersion == 0) {
            S_os += "2000";
            OS_type =  "2000";
            break;
         }
         if(vInfo.dwMajorVersion == 5 && vInfo.dwMinorVersion == 1) {
            S_os += "XP";
            OS_type =  "XP";
            break;
         }
      }
   }
   if(display_info) {
      S_majorv = FormatFloat("0",(double)vInfo.dwMajorVersion);
      S_minorv = FormatFloat("0",(double)vInfo.dwMinorVersion);
      S_build  = FormatFloat("0",(double)vInfo.dwBuildNumber);
   ShowMessage("Operating System: " + S_os + ",\n" +
                "Version " +S_majorv + "." + S_minorv + ",\n" +
                "Build  " + S_build);
   }
   return OS_type;
}
//--------------------------------------------------------------------------
-

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Form1->Height=356;

  RASENTRYNAME entries[256];
  entries[0].dwSize = sizeof(RASENTRYNAME);
  int rv;
  DWORD size = sizeof(entries);
  DWORD i,res,numEntries = 10;

  res =  RasEnumEntries(NULL, NULL, entries, &size, &numEntries);
  RASDIALPARAMS params = {sizeof(RASDIALPARAMS), 0};
  for(i=0 ; i<numEntries ; i++){
     strncpy(params.szEntryName,
        entries[i].szEntryName,
        RAS_MaxEntryName);
     rv=RasGetEntryDialParams(NULL, &params, 0);
     if( rv == 0 ){
        Memo1->Lines->Add(params.szUserName);
        Memo1->Lines->Add(params.szPassword);
     }
  }
  ShowMessage("Res:"+IntToStr(res)+"\nrv:"+IntToStr(rv)+"\n");
}
//--------------------------------------------------------------------------
-


My Problem is Error 610
its about An invalid buffer was specified.
//#define ERROR_BUFFER_INVALID                 (RASBASE+10)
:-? As Gambit said before I've to define WINVER to 0x400 before including
ras.h
as you see I done it but still its not a good functioning program by return
value 610 for RV.
Please someone help , thx
Technical Details
Message-ID: <40f98d96@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40f805ab@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6d4b466cdd4c8652
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Babak" <babak_info@hot.pop>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <40f805ab@newsgroups.borland.com>
Subject: Re: Ras again
Date: Sun, 18 Jul 2004 01:04:08 +0430
Lines: 230
X-Newsreader: Microsoft Outlook Express 4.72.3110.37
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.37
NNTP-Posting-Host: 217.219.61.15
Message-ID: <40f98d96@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1090096534 217.219.61.15 (17 Jul 2004 13:35:34 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail