Jump to content

Problem in RasEnumConnections calling.


Recommended Posts

 

Global Const $RAS_MaxAreaCode = 10
Global Const $RAS_MaxPhoneNumber = 128
Global Const $RAS_MaxDeviceType = 16
Global Const $RAS_MaxDeviceName = 128
Global Const $RAS_MaxPadType = 32
Global Const $RAS_MaxX25Address = 200
Global Const $RAS_MaxFacilities = $RAS_MaxX25Address
Global Const $RAS_MaxUserData = $RAS_MaxFacilities
Global Const $RAS_MaxDnsSuffix = 256
Global Const $RAS_MaxEntryName = 256
Global Const $WM_RASDIALEVENT = 0xCCCD
Global Const $RASCS_DONE = 0x2000
Global Const $WAIT_OBJECT_0 = 0
Global $hConection = 0
Global Const $MAX_PATH = 256
Global Const $tagRASDIALPARAMS = "dword dwSize;handle hrasconn;wchar szEntryName["& $RAS_MaxEntryName +1 &"];wchar szDeviceType["&$RAS_MaxDeviceType + 1&"];wchar szDeviceName["&$RAS_MaxDeviceName + 1&"];wchar szPhonebook["&$MAX_PATH &"];DWORD dwSubEntry;GUID guidEntry;DWORD dwFlags; LUID luid;GUID guidCorrelationId"
Local $tRASDIALPARAMS = DllStructCreate($tagRASDIALPARAMS)
Sleep(100)
DllStructSetData($tagRASDIALPARAMS,"dwSize", DllStructGetSize($tRASDIALPARAMS))
$lpcb = DllStructGetSize($tRASDIALPARAMS)
Local $iRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnectionsW", "ptr",$tRASDIALPARAMS,"dword",$lpcb, "ptr",$tRASDIALPARAMS)

MsgBox(0,"",$iRet[0])

 

I got error 87(The parameter is incorrect)......if you can help me i shall be very grateful to you.

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

Hello,

the error 87 is rightly ... ;)

1. the data type GUID and LUID does not exist. These are own Structures.
2. the parameters for RasEnumConnections are all of type pointer and must be passed so

3. with a null pointer call you get the buffer size needed
....

Try times so I could not test!

#include <Array.au3>

Global Const $RAS_MaxAreaCode = 10
Global Const $RAS_MaxPhoneNumber = 128
Global Const $RAS_MaxDeviceType = 16
Global Const $RAS_MaxDeviceName = 128
Global Const $RAS_MaxPadType = 32
Global Const $RAS_MaxX25Address = 200
Global Const $RAS_MaxFacilities = $RAS_MaxX25Address
Global Const $RAS_MaxUserData = $RAS_MaxFacilities
Global Const $RAS_MaxDnsSuffix = 256
Global Const $RAS_MaxEntryName = 256
Global Const $WM_RASDIALEVENT = 0xCCCD
Global Const $RASCS_DONE = 0x2000
Global Const $WAIT_OBJECT_0 = 0
Global $hConection = 0
Global Const $MAX_PATH = 256

Global Const $tagGUID = "struct;DWORD GUID_Data1;WORD GUID_Data2;WORD GUID_Data3;BYTE GUID_Data[8];endstruct"
Global Const $tagLUID = "struct;DWORD LUID_LowPart;LONG LUID_HighPart;endstruct"
Global Const $tagRASCONN = "struct;dword dwSize;handle hrasconn;wchar szEntryName[" & $RAS_MaxEntryName + 1 & "];wchar szDeviceType[" & $RAS_MaxDeviceType + 1 & "];wchar szDeviceName[" & $RAS_MaxDeviceName + 1 & "];wchar szPhonebook[" & $MAX_PATH & "];DWORD dwSubEntry;" & $tagGUID & ";DWORD dwFlags;" & $tagLUID & ";" & $tagGUID & ";endstruct"

Global Const $tagREC_lpcb = "dword lpcb"
Global Const $tagRec_lpcConns = "dword lpcConns"

Local $tREC_lpcb = DllStructCreate($tagREC_lpcb)
Local $tREC_lpcConns = DllStructCreate($tagRec_lpcConns)

Sleep(100)

; get the required buffer size
DllStructSetData($tREC_lpcb, "lpcb", 0)
DllStructSetData($tREC_lpcConns, "lpcConns", 0)
Local $aRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnections", "ptr", Null, "ptr", DllStructGetPtr($tREC_lpcb), "ptr", DllStructGetPtr($tREC_lpcConns))

MsgBox(0, "get buffer size", $aRet[0])

ConsoleWrite("required buffer size: " & DllStructGetData($tREC_lpcb, "lpcb") & @CRLF) ; the required buffer size
ConsoleWrite("Number of RASCON Structures: " & DllStructGetData($tREC_lpcConns, "lpConns") & @CRLF) ; mumber of RASCON Structures

If $aRet[0] = 603 Then ; ERROR_BUFFER_TOO_SMALL
    $iConns = DllStructGetData($tREC_lpcConns, "lpConns")

    $tagRASCONNS = ""
    For $iStructs = 1 To $iConns
        $tagRASCONNS &= StringRegExpReplace($tagRASCONN, "\s+(.*?);", " RC" & $iStructs & "_$1" &";") & ";"
    Next

;~  ConsoleWrite($tagRASCONNS & @CRLF)
    $tRASCONNS = DllStructCreate($tagRASCONNS)
    $iRASCONN_size = DllStructGetSize(DllStructCreate($tagRASCONN))
;~ ConsoleWrite($iRASCONN_size & @CRLF)

    For $iStructs = 1 To $iConns
        DllStructSetData($tRASCONNS, "RC" & $iStructs & "_dwSize", $iRASCONN_size)
    Next

    DllStructSetData($tREC_lpcb, "lpcb", DllStructGetSize($tRASCONNS))
    $aRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnections", "ptr",DllStructGetPtr($tRASCONNS),"ptr",DllStructGetPtr($tREC_lpcb), "ptr",DllStructGetPtr($tREC_lpcConns))

    MsgBox(0, "get data", $aRet[0])

    For $iStructs = 1 To $iConns
        ConsoleWrite("EntryName of Conn " & $iStructs & ": " & DllStructGetData($tRASCONNS, "RC" & $iStructs & "_szEntryName") & @CRLF)
    Next
EndIf

 

 

Edited by bernd670
Correct Code

greetings
bernd


I hacked 127.0.0.1 -> pcfred6.gif

Link to comment
Share on other sites

Hello,

the error 87 is rightly ... ;)

1. the data type GUID and LUID does not exist. These are own Structures.
2. the parameters for RasEnumConnections are all of type pointer and must be passed so

3. with a null pointer call you get the buffer size needed
....

Try times so I could not test!

Hidden Content

 

​Bro it is not working......

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

hi mate. trying with rasdial again. :) This should work. and should returns the buffer required size.

 

Global Const $ERROR_SUCCESS = 0x0
Global Const $RAS_MaxAreaCode = 10
Global Const $RAS_MaxPhoneNumber = 128
Global Const $RAS_MaxDeviceType = 16
Global Const $RAS_MaxDeviceName = 128
Global Const $RAS_MaxPadType = 32
Global Const $RAS_MaxX25Address = 200
Global Const $RAS_MaxFacilities = $RAS_MaxX25Address
Global Const $RAS_MaxUserData = $RAS_MaxFacilities
Global Const $RAS_MaxDnsSuffix = 256
Global Const $RAS_MaxEntryName = 256
Global Const $WM_RASDIALEVENT = 0xCCCD
Global Const $RASCS_DONE = 0x2000
Global Const $WAIT_OBJECT_0 = 0
Global $hConection = 0
Global Const $MAX_PATH = 256
Global Const $tagRASDIALPARAMS = "dword dwSize;handle hrasconn;wchar szEntryName[" & $RAS_MaxEntryName + 1 & "];wchar szDeviceType[" & $RAS_MaxDeviceType + 1 & "];wchar szDeviceName[" & $RAS_MaxDeviceName + 1 & "];wchar szPhonebook[" & $MAX_PATH & "];DWORD dwSubEntry;GUID guidEntry;DWORD dwFlags; LUID luid;GUID guidCorrelationId"
Local $tRASDIALPARAMS = DllStructCreate($tagRASDIALPARAMS)
Sleep(100)
DllStructSetData($tagRASDIALPARAMS, "dwSize", DllStructGetSize($tRASDIALPARAMS))
$lpcb = DllStructGetSize($tRASDIALPARAMS)


Local $iRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnectionsW", "ptr", 0, "dword*", Null, "ptr*", 0)

If Not ($iRet[0] = $ERROR_SUCCESS) Then
    Local $tpcbSize = $iRet[2]
    MsgBox(0, "required buffer size", $tpcbSize)
Else
    MsgBox(0, "There are no active RAS connections", $tpcbSize)
EndIf

Saludos

Link to comment
Share on other sites

Hello,
which values are to be returned?

Oh I see now I forgot index in the following line

If $aRet = 603 Then ; ERROR_BUFFER_TOO_SMALL

correct is

If $aRet[0] = 603 Then ; ERROR_BUFFER_TOO_SMALL

 

​But the error remain same 603(buffer is too small)

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

hi mate. trying with rasdial again. :) This should work. and should returns the buffer required size.

 

Global Const $ERROR_SUCCESS = 0x0
Global Const $RAS_MaxAreaCode = 10
Global Const $RAS_MaxPhoneNumber = 128
Global Const $RAS_MaxDeviceType = 16
Global Const $RAS_MaxDeviceName = 128
Global Const $RAS_MaxPadType = 32
Global Const $RAS_MaxX25Address = 200
Global Const $RAS_MaxFacilities = $RAS_MaxX25Address
Global Const $RAS_MaxUserData = $RAS_MaxFacilities
Global Const $RAS_MaxDnsSuffix = 256
Global Const $RAS_MaxEntryName = 256
Global Const $WM_RASDIALEVENT = 0xCCCD
Global Const $RASCS_DONE = 0x2000
Global Const $WAIT_OBJECT_0 = 0
Global $hConection = 0
Global Const $MAX_PATH = 256
Global Const $tagRASDIALPARAMS = "dword dwSize;handle hrasconn;wchar szEntryName[" & $RAS_MaxEntryName + 1 & "];wchar szDeviceType[" & $RAS_MaxDeviceType + 1 & "];wchar szDeviceName[" & $RAS_MaxDeviceName + 1 & "];wchar szPhonebook[" & $MAX_PATH & "];DWORD dwSubEntry;GUID guidEntry;DWORD dwFlags; LUID luid;GUID guidCorrelationId"
Local $tRASDIALPARAMS = DllStructCreate($tagRASDIALPARAMS)
Sleep(100)
DllStructSetData($tagRASDIALPARAMS, "dwSize", DllStructGetSize($tRASDIALPARAMS))
$lpcb = DllStructGetSize($tRASDIALPARAMS)


Local $iRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnectionsW", "ptr", 0, "dword*", Null, "ptr*", 0)

If Not ($iRet[0] = $ERROR_SUCCESS) Then
    Local $tpcbSize = $iRet[2]
    MsgBox(0, "required buffer size", $tpcbSize)
Else
    MsgBox(0, "There are no active RAS connections", $tpcbSize)
EndIf
 

Saludos

​My dear error Remain same 603(buffer is to small)::: required buffer is 1384 in this on my pc....... 

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

 

Simply use $tpcSize to allocate memory. $tpcSize 

I wanted to mean this:

 

Local $iRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnectionsW", "ptr", 0, "dword*", Null, "ptr*", 0)

If $iRet[0] = $ERROR_BUFFER_TOO_SMALL Then
    Local $tpcbSize = $iRet[2]
    MsgBox(0, "required buffer size", $tpcbSize)
    Local $tBuffer=DllStructCreate("byte[" & $tpcbSize & "]")
    ;then call RasEnumConnectionsW again
Else
    MsgBox(0, "There are no active RAS connections", $tpcbSize)
EndIf

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

Hello,

I have a mistake, I can try not unfortunately, sorry!

in the following line is missing a 'c', therefore can not determine the required buffer size!

$iConns = DllStructGetData($tREC_lpcConns, "lpConns")

change to

$iConns = DllStructGetData($tREC_lpcConns, "lpcConns")

sorry ;)

Edited by bernd670

greetings
bernd


I hacked 127.0.0.1 -> pcfred6.gif

Link to comment
Share on other sites

#include <Array.au3>

Global Const $RAS_MaxAreaCode = 10
Global Const $RAS_MaxPhoneNumber = 128
Global Const $RAS_MaxDeviceType = 16
Global Const $RAS_MaxDeviceName = 128
Global Const $RAS_MaxPadType = 32
Global Const $RAS_MaxX25Address = 200
Global Const $RAS_MaxFacilities = $RAS_MaxX25Address
Global Const $RAS_MaxUserData = $RAS_MaxFacilities
Global Const $RAS_MaxDnsSuffix = 256
Global Const $RAS_MaxEntryName = 256
Global Const $WM_RASDIALEVENT = 0xCCCD
Global Const $RASCS_DONE = 0x2000
Global Const $WAIT_OBJECT_0 = 0
Global $hConection = 0
Global Const $MAX_PATH = 256

Global Const $tagGUID = "struct;DWORD GUID_Data1;USHORT GUID_Data2;USHORT GUID_Data3;BYTE GUID_Data[8];endstruct"
Global Const $tagLUID = "struct;DWORD LUID_LowPart;LONG LUID_HighPart;endstruct"
Global Const $tagRASCONN = "struct;dword dwSize;handle hrasconn;char szEntryName[" & $RAS_MaxEntryName + 1 & "];char szDeviceType[" & $RAS_MaxDeviceType + 1 & "];char szDeviceName[" & $RAS_MaxDeviceName + 1 & "];char szPhonebook[" & $MAX_PATH & "];DWORD dwSubEntry;" & $tagGUID & ";DWORD dwFlags;" & $tagLUID & ";" & $tagGUID & ";endstruct"

Global Const $tagREC_lpcb = "dword lpcb"
Global Const $tagRec_lpcConns = "dword lpcConns"

Local $tREC_lpcb = DllStructCreate($tagREC_lpcb)
Local $tREC_lpcConns = DllStructCreate($tagRec_lpcConns)

Sleep(100)

; get the required buffer size
DllStructSetData($tREC_lpcb, "lpcb", 0)
DllStructSetData($tREC_lpcConns, "lpcConns", 0)
Local $aRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnections", "ptr", Null, "ptr", DllStructGetPtr($tREC_lpcb), "ptr", DllStructGetPtr($tREC_lpcConns))

MsgBox(0, "get buffer size", $aRet[0])

ConsoleWrite("required buffer size: " & DllStructGetData($tREC_lpcb, "lpcb") & @CRLF) ; the required buffer size
ConsoleWrite("Number of RASCON Structures: " & DllStructGetData($tREC_lpcConns, "lpConns") & @CRLF) ; mumber of RASCON Structures

If $aRet[0] = 603 Then ; ERROR_BUFFER_TOO_SMALL
    $iConns = DllStructGetData($tREC_lpcConns, "lpcConns")

    $tagRASCONNS = ""
    For $iStructs = 1 To $iConns
        $tagRASCONNS &= StringRegExpReplace($tagRASCONN, "\s+(.*?);", " RC" & $iStructs & "_$1" &";") & ";"
    Next

;~  ConsoleWrite($tagRASCONNS & @CRLF)
    $tRASCONNS = DllStructCreate($tagRASCONNS)
    $iRASCONN_size = DllStructGetSize(DllStructCreate($tagRASCONN))
;~ ConsoleWrite($iRASCONN_size & @CRLF)

    For $iStructs = 1 To $iConns
        DllStructSetData($tRASCONNS, "RC" & $iStructs & "_dwSize", $iRASCONN_size)
    Next

    DllStructSetData($tREC_lpcb, "lpcb", DllStructGetSize($tRASCONNS))
    $aRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnections", "ptr",DllStructGetPtr($tRASCONNS),"ptr",DllStructGetPtr($tREC_lpcb), "ptr",DllStructGetPtr($tREC_lpcConns))

    MsgBox(0, "get data", $aRet[0])

    For $iStructs = 1 To $iConns
        ConsoleWrite("EntryName of Conn " & $iStructs & ": " & DllStructGetData($tRASCONNS, "RC" & $iStructs & "_szEntryName") & @CRLF)
    Next
EndIf

Now i got error 632 (The structure size is incorrect)

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

Let me see If I found my usb flash memory I think I have an example i write some time ago.

 

Saludos

Link to comment
Share on other sites

I search in my work and house and I could no find my usb. so I write the example again.

 

#include <Array.au3>
Global Const $ERROR_SUCCESS = 0x0
Global Const $ERROR_BUFFER_TOO_SMALL = 603
Global Const $RAS_MaxAreaCode = 10
Global Const $RAS_MaxPhoneNumber = 128
Global Const $RAS_MaxDeviceType = 16
Global Const $RAS_MaxDeviceName = 128
Global Const $RAS_MaxPadType = 32
Global Const $RAS_MaxX25Address = 200
Global Const $RAS_MaxFacilities = $RAS_MaxX25Address
Global Const $RAS_MaxUserData = $RAS_MaxFacilities
Global Const $RAS_MaxDnsSuffix = 256
Global Const $RAS_MaxEntryName = 256
Global Const $WM_RASDIALEVENT = 0xCCCD
Global Const $RASCS_DONE = 0x2000
Global Const $WAIT_OBJECT_0 = 0
Global $hConection = 0
Global Const $MAX_PATH = 256

Global Const $tagGUID = "struct;DWORD GUID_Data1;USHORT GUID_Data2;USHORT GUID_Data3;BYTE GUID_Data[8];endstruct"
Global Const $tagLUID = "struct;DWORD LUID_LowPart;LONG LUID_HighPart;endstruct"
;Your $tagRASCONN was wrong (I think you're over window 7 or 8 you should see respective declaration using macros. I'll add you the C++ typedef at the end.
Global Const $tagRASCONN = "struct;dword dwSize;handle hrasconn;wchar szEntryName[" & $RAS_MaxEntryName + 1 & "];wchar szDeviceType[" & $RAS_MaxDeviceType + 1 & "];wchar szDeviceName[" & $RAS_MaxDeviceName + 1 & "]"


Local $iRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnectionsW", "ptr", 0, "dword*", Null, "ptr*", 0) ;Call For get the required buffer size

If $iRet[0] = $ERROR_BUFFER_TOO_SMALL Then
    Local $tpcbSize = $iRet[2]
    MsgBox(0, "required buffer size", $tpcbSize)
    Local $tBuffer = DllStructCreate("dword dwSize;byte[" & $tpcbSize - 4 & "]") ;create a Buffer this is the array of RASCONN Structures
    Local $tRASCONNSize = DllStructCreate($tagRASCONN);Just For Get The Size
    Local $iRASCONNSize = DllStructGetSize($tRASCONNSize) ;Just For Get The Size
    $tRASCONNSize = 0 ;Free
    $tBuffer.dwSize = $iRASCONNSize ;Fill the first dwSize of the array of RASCONN Structures

    $iRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnectionsW", "ptr", DllStructGetPtr($tBuffer), "dword*", $tpcbSize, "dword*", 0) ;call For Get the Datas

    If $iRet[0] = $ERROR_SUCCESS Then
        Local $iConnections = $iRet[3]
        Local $atRasConn[$iConnections] ;Create an array of RASCONN Structures
        ;This is not the best way to do it :) (I gone fast)
        For $i = 1 To $iConnections
            $atRasConn[$i - 1] = DllStructCreate($tagRASCONN, DllStructGetPtr($tBuffer) + (($i - 1) * $iRASCONNSize)) ;Create the array of structure supplying the buffer Pointer using as index the RASCONN size
            MsgBox(0, "Conection " & $i, "szEntryName: " & $atRasConn[$i - 1].szEntryName)
        Next

    EndIf

Else
    MsgBox(0, "", "There are no active RAS connections")
EndIf

;then Free everything :)

here is the type def for unicode.

typedef struct tagRASCONNW {
    DWORD dwSize;
    HRASCONN hrasconn;
    WCHAR szEntryName[RAS_MaxEntryName + 1];
#if (WINVER >= 0x400) 
    WCHAR szDeviceType[RAS_MaxDeviceType + 1];
    WCHAR szDeviceName[RAS_MaxDeviceName + 1];
#endif
#if (WINVER >= 0x401)
    WCHAR szPhonebook[MAX_PATH];
    DWORD dwSubEntry;
#endif
#if (WINVER >= 0x500)
    GUID guidEntry;
#endif
#if (WINVER >= 0x501)
    DWORD dwFlags;
    LUID luid;
#endif
} RASCONNW, *LPRASCONNW;

 

 

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

There are apparently different definitions of struct RASCONN, thank Danyfirex.


Moreover, the length of MAX_PATH was wrong.
Stupid that I can not test it!

#include <Array.au3>

Global Const $RAS_MaxAreaCode = 10
Global Const $RAS_MaxPhoneNumber = 128
Global Const $RAS_MaxDeviceType = 16
Global Const $RAS_MaxDeviceName = 128
Global Const $RAS_MaxPadType = 32
Global Const $RAS_MaxX25Address = 200
Global Const $RAS_MaxFacilities = $RAS_MaxX25Address
Global Const $RAS_MaxUserData = $RAS_MaxFacilities
Global Const $RAS_MaxDnsSuffix = 256
Global Const $RAS_MaxEntryName = 256
Global Const $WM_RASDIALEVENT = 0xCCCD
Global Const $RASCS_DONE = 0x2000
Global Const $WAIT_OBJECT_0 = 0
Global $hConection = 0
Global Const $MAX_PATH = 260

Global Const $tagGUID = "struct;DWORD GUID_Data1;WORD GUID_Data2;WORD GUID_Data3;BYTE GUID_Data[8];endstruct"
Global Const $tagLUID = "struct;DWORD LUID_LowPart;LONG LUID_HighPart;endstruct"
Global Const $tagRASCONN = "align 4;struct;dword dwSize;handle hrasconn;wchar szEntryName[" & $RAS_MaxEntryName + 1 & "];wchar szDeviceType[" & $RAS_MaxDeviceType + 1 & "];wchar szDeviceName[" & $RAS_MaxDeviceName + 1 & "];wchar szPhonebook[" & $MAX_PATH & "];DWORD dwSubEntry;" & $tagGUID; & ";DWORD dwFlags;" & $tagLUID & ";" & $tagGUID & ";endstruct"

Global Const $tagREC_lpcb = "dword lpcb"
Global Const $tagRec_lpcConns = "dword lpcConns"

Local $tREC_lpcb = DllStructCreate($tagREC_lpcb)
Local $tREC_lpcConns = DllStructCreate($tagRec_lpcConns)

Sleep(100)

; get the required buffer size
DllStructSetData($tREC_lpcb, "lpcb", 0)
DllStructSetData($tREC_lpcConns, "lpcConns", 0)
Local $aRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnections", "ptr", Null, "ptr", DllStructGetPtr($tREC_lpcb), "ptr", DllStructGetPtr($tREC_lpcConns))

MsgBox(0, "get buffer size", "Error Code: " & $aRet[0] & @CRLF & "required buffer size: " & DllStructGetData($tREC_lpcb, "lpcb") & @CRLF & "number of RASCONN Structures: "  & DllStructGetData($tREC_lpcConns, "lpcConns") & @CRLF )

ConsoleWrite("required buffer size: " & DllStructGetData($tREC_lpcb, "lpcb") & @CRLF) ; the required buffer size
ConsoleWrite("Number of RASCON Structures: " & DllStructGetData($tREC_lpcConns, "lpcConns") & @CRLF) ; mumber of RASCON Structures

If $aRet[0] = 603 Then ; ERROR_BUFFER_TOO_SMALL
    $iConns = DllStructGetData($tREC_lpcConns, "lpcConns")

    $tagRASCONNS = ""
    For $iStructs = 1 To $iConns
        $tagRASCONNS &= StringRegExpReplace($tagRASCONN, "\s+(.*?);", " RC" & $iStructs & "_$1" & ";") & ";"
    Next

;~  ConsoleWrite($tagRASCONNS & @CRLF)
    $tRASCONNS = DllStructCreate($tagRASCONNS)
    $iRASCONN_size = DllStructGetSize(DllStructCreate($tagRASCONN))
;~ ConsoleWrite($iRASCONN_size & @CRLF)

    For $iStructs = 1 To $iConns
        DllStructSetData($tRASCONNS, "RC" & $iStructs & "_dwSize", $iRASCONN_size)
    Next
    ConsoleWrite("Size of Struct:" & DllStructGetSize($tRASCONNS) & @CRLF)
    DllStructSetData($tREC_lpcb, "lpcb", DllStructGetSize($tRASCONNS))
    $aRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnections", "ptr", DllStructGetPtr($tRASCONNS), "ptr", DllStructGetPtr($tREC_lpcb), "ptr", DllStructGetPtr($tREC_lpcConns))

    MsgBox(0, "get data", "Error Code: " & $aRet[0] & @CRLF & "Size of Struct:" & DllStructGetSize($tRASCONNS) & @CRLF)

    For $iStructs = 1 To $iConns
        ConsoleWrite("EntryName of Conn " & $iStructs & ": " & DllStructGetData($tRASCONNS, "RC" & $iStructs & "_szEntryName") & @CRLF)
    Next
EndIf

Edit:

In https://msdn.microsoft.com/en-us/library/windows/desktop/aa376725(v=vs.85).aspx is the following comment:

Please add structure alignment 4 bytes

In x64, this structure should be aligned to 4 bytes.

 

Otherwise the dwSize calculated by sizeof(RASCONN) is not accepted by RasEnumConnections().

 

Please add structure alignment 4 bytes.

I have inserted also times in the struct

Edited by bernd670

greetings
bernd


I hacked 127.0.0.1 -> pcfred6.gif

Link to comment
Share on other sites

Thanks to all(Who gave this platform) but special thanks goes to Danyfirex and bernd 670

Danyfirex Your last code is working fine for me..........Thanks.

bernd670After changing wchar to char in $tagRASCONN structure your code is also work fine for me thanks.

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...