Sign in to follow this  
Followers 0
Inververs

Array as a parameter for dllcall

4 posts in this topic

Hellp! I try to enumerate dial-in (VPN, virtual private network) connections names whith this function

Private Declare Function RasEnumEntries Lib "rasapi32.dll" Alias "RasEnumEntriesA" (ByVal lpcstr As String, ByVal lpcstr As String, ByRef lprasentrynamea As Any, ByRef lpdword As Long, ByRef lpdword As Long) As Long

=========================================

Basic source code look like

=========================================

Private Type RASENTRYNAME       ' Получение имен соединений
   dwSize                       As Long
   szEntryName(RAS_MaxEntryName) As Byte
End Type


 Dim rsname()  As RASENTRYNAME
    Dim lSize    As Long

    ReDim rsname(0) As RASENTRYNAME

    rsname(0).dwSize = &H108
    lSize = rsname(0).dwSize
                                                                   
    RasEnumEntries(vbNullString, vbNullString, rsname(0), lSize, GetRasEntrLst)

Where GetRasEntrLst - number of connections

=========================================

Delphi source code:

=========================================

BuffSize: Integer; 
Entries: Integer;
Entry : Array[1..MaxEntries] of TRasEntryName; 
AllEntries: TStrings;

Entry[1].dwSize:=SizeOf(TRasEntryName);
(consisting of an array of variables, which will be posted about the "remote connections", where the constant MaxEntries - the number of possible connections, TRasEntryName - definition (type) record of two fields and dwSize szEntryName (defined in RasUnit.pas))


BuffSize:=SizeOf(TRasEntryName)*MaxEntries;  

Result_:=RasEnumEntries(nil, nil, @Entry[1], BuffSize, Entries)

=========================================

I try in autoit

$GetRasEntrLst=''
$vbNullString=Chr(0)
$RAS_MaxEntryName=0x100

$TRasEntryName=DllStructCreate("long dwSize;Byte szEntryName["&$RAS_MaxEntryName&"]")
DllStructSetData($TRasEntryName,1,0x108)
$a=DllCall("rasapi32.dll","int","RasEnumEntries","str", $vbNullString ,"str",$vbNullString,"ptr",DllStructGetPtr($TRasEntryName),"int",0x100,"int",$GetRasEntrLst)

but variable $GetRasEntrLst always equal to zero :P:(:P

...how to define an array (Entry : Array[100] of TRasEntryName;) and transmit it to function?

Share this post


Link to post
Share on other sites



this is claer :P if you want to get a return value in parameter, you have to use

int*

And then get it from the return-Array :P ( it is the 5th parameter) :

$GetRasEntrLst = $TRasEntryName[5]


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

this is claer :P if you want to get a return value in parameter, you have to use

int*

And then get it from the return-Array :P ( it is the 5th parameter) :

$GetRasEntrLst = $TRasEntryName[5]

i try whith "int*"

$a=DllCall("rasapi32.dll","int","RasEnumEntries","str", $vbNullString ,"str",$vbNullString,"ptr",DllStructGetPtr($TRasEntryName),"int",0x100,"int*",$GetRasEntrLst)
is zero :o

This function must put the result in an array of $TRasEntryName, where the field "szEntryName" names connections

Names -> to listbox in delphi.

If (Result_=0) and (Entries>0) Then
AllEntries:= TStringList.Create;
Begin
For X:=1 To Entries Do
    Begin
        AllEntries.Add(Entry[x].szEntryName);
    End;
End;

and how do the same in autoit...

Edited by Odin

Share this post


Link to post
Share on other sites

a little bit late for an answer but here we go:

#include <Memory.au3>
;~ ;===============================================================================
;~ ; Description:      Returns the RAS-Entrie information in an array.
;~ ; Author:           VoSso2o0o
;~ ; Parameter(s):     None
;~ ; Requirement(s):   #include-once <Memory.au3>
;~ ; Return Value(s):  On Success - Returns array of Ras entries
;~ ;                   On Failure - @error <> 0 (Windows Error Number) and Returns 0
;- ;
;~ ; Note(s):
;~ ;===============================================================================

Func _RasEnumEntries()

  const $SUCCESS = 0
  const $ERROR_NOT_ENOUGH_MEMORY = 8
  const $RASBASE = 600
  const $ERROR_BUFFER_TOO_SMALL = $RASBASE + 3
  const $ERROR_INVALID_SIZE = $RASBASE + 32
  Dim $result[1]

  $RAS_MaxEntryName=0x104                                                                            ;don't no why it is not 0x100....
  $RasEntryName = "int dwSize;char szEntryName["&$RAS_MaxEntryName&"]"                               ;RASENTRYNAME structure data
  $TRasEntryName = DllStructCreate($RasEntryName)                                                    ;temporary Structure for sizing
  $RAS_EntryName_Size = DllStructGetSize($TRasEntryName)                                             ;Structure Size

  $mem = _MemGlobalAlloc(256 * $RAS_EntryName_Size, $GPTR)                                           ;Allocate Memory for Array
  Dim $ARasEntryName[256]                                                                            ;Create an Array [256] for Param 3

  For $i=0 to 255
    $ARasEntryName[$i] = DllStructCreate($RasEntryName, $mem + ($i * $RAS_EntryName_Size))           ;Create 256 Structures in the Array
  next
  $lpcb = 256*$RAS_EntryName_Size                                                                    ;calc BufferSize (Param4)
  $lpcEntries = 0                                                                                    ;Init Param5
  DllStructSetData($ARasEntryName[0],1, $RAS_EntryName_Size)                                         ;write StructureSize to first member of the array

  ;DWORD RasEnumEntries( __in     LPCTSTR reserved, __in     LPCTSTR lpszPhonebook, __inout  LPRASENTRYNAME lprasentryname, __inout  LPDWORD lpcb, __out    LPDWORD lpcEntries);
  $res = DllCall("rasapi32.dll","int","RasEnumEntries","ptr", 0,"ptr",0,"ptr",DllStructGetPtr($ARasEntryName[0]),"int*",$lpcb,"int*",$lpcEntries)
  ;ConsoleWrite($res[0] & @LF)
  if $res[0]=0 then                                                                                  ;Return Value
    ;ConsoleWrite($res[4] & @LF)                                                                     ;Length in Bytes
    $noEntries =  $res[5]                                                                            ;number of Entries
    for $i = 0 to $noEntries - 1
      $result[$i] = DllStructGetData ( $ARasEntryName[$i], "szEntryName")                            ;copy result to result-Array
      ;ConsoleWrite($result[$i])
      Redim $result[Ubound($result) + 1]                                                             ;resize result-Array
      ;ConsoleWrite(DllStructGetData ( $ARasEntryName[$i], "szEntryName") & @LF)
    next
    Redim $result[Ubound($result) - 1]                                                               ;delete last (empty) entry
    Return $result
  Else
    SetError($res[0], 0, 0)
  endif
endfunc

$ras = _RasEnumEntries()

AutoItMacroGenerator on my Homepage (Link 2)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0