Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

rasapi32.dll call help

$
0
0

Hi all, I'm after some help with Dll calls because I'd like remove dependance on a CLI command.

I've got a small script that I've created as a simple VPN connection indicator that toggles a tray icon depending on monitored Events, (ID 20267 and 20268), but to get the initial state I make a call to rasdial.exe and parse the output.

Here's what I use to get the VPN status at program start:
 

AutoIt         
#include <Constants.au3> ConsoleWrite(_GetVPNState() & @CRLF) Func _GetVPNState() ; Calls rasdial.exe to get initial VPN state     While ProcessExists("rasdial.exe")         Sleep(250)     WEnd     Local $temp = Run(@ComSpec & ' /c rasdial.exe', '.', @SW_HIDE, $STDOUT_CHILD)     If @error Then         MsgBox(24, "VPN Indicator", "Failed to run rasdial.exe for initial state", 5)     EndIf     Local $output = ""     While True         $output &= StdoutRead($temp)         If @error <> 0 Then ExitLoop     WEnd     StdioClose($temp)     If StringInStr($output, "No connections") = 0 Then         $temp = StringSplit($output, @CRLF)         $sConnection = $temp[2] ; Phonebook entry name     Else         $sConnection = "Not connected"     EndIf     Return $sConnection EndFunc   ;==>_GetVPNState

I'd like to use rasapi32.dll for the required call but I can't seem to wrap my head around the required Dll* statements for the functions: RasEnumConnections and RasGetConnectStatus.
 

Below is what I've been playing with just trying to get a buffer size back from the function, (for when a VPN is active), I'm not having much luck.

AutoIt         
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Version=Beta #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Global $rasdll = "rasapi32.dll" $tagRASCONNdata = "dword dwSize;" & _         "handle hrasconn;" & _         "wchar szEntryName[256];" & _         "wchar szDeviceType[256];" & _         "wchar szDeviceName[128];" & _         "wchar szPhonebook[128];" & _         "dword dwSubEntry;" & _         "byte guidEntry[16];" & _         "dword dwFlags;" & _         "int64 luid;" & _         "byte guidCorrelationId[16]" $hDll = DllOpen($rasdll) If @error Then Exit MsgBox(0, "", "DllOpen error: " & @error) ConsoleWrite("DLL handle: " & $hDll & @CRLF) Local $tRASCONN = DllStructCreate($tagRASCONNdata) If @error Then Exit MsgBox(0, "", "DllStructCreate error: " & @error) DllStructSetData($tRASCONN, "Size", DllStructGetSize($tRASCONN)) ConsoleWrite("DLLStructure: " & DllStructGetSize($tRASCONN) & @CRLF) Local $iBufferSize = 0 Local $NULL = NULL ; Call RasEnumConnections with NULL and 0 to return required buffer size $iRet = DllCall($hDll, "int", "RasEnumConnectionsW", "ptr", $NULL, "ptr", $iBufferSize, "ptr", DllStructGetPtr($tRASCONN)) ConsoleWrite("DllCall return: " & $iRet & @CRLF) ConsoleWrite("Buffer size: " & $iBufferSize & @CRLF) DllClose($hDll)

I'd be grateful if someone could point me at an example that approximates what I want to do, ie. same kind of function with data structure, etc, so I can get an idea of how I should be doing it.

 

Alternatively, If someone is hiding a long lost RAS UDF on their drive I'd be even more grateful :idiot:

 

Below is the links to the functions I want to use, thanks for any help.

 

http://msdn.microsoft.com/en-us/library/windows/desktop/aa377284%28v=vs.85%29.aspx
DWORD RasEnumConnections(
    _Inout_  LPRASCONN lprasconn,    ;    OUT: Pointer to buffer of RASCONN structures  IN: Set sizeof(RASCONN) on first entry
    _Inout_  LPDWORD lpcb,                ;    IN: Size of buffer in bytes  OUT: Number of bytes req to enumerate RAS connections
    _Out_    LPDWORD lpcConnections    ; Number of RASCONN structures in buffer
);

http://msdn.microsoft.com/en-us/library/windows/desktop/aa376725%28v=vs.85%29.aspx
RASCONN Structure
typedef struct & _RASCONN {
    DWORD            dwSize;            ; sizeof(RASSCON)
    HRASCONN        hrasconn;            ; HRASCONN handle that defines the remote access connection.
    TCHAR                szEntryName[RAS_MaxEntryName + 1];
    TCHAR                szDeviceType[RAS_MaxDeviceType + 1];
    TCHAR                szDeviceName[RAS_MaxDeviceName + 1];
    TCHAR                szPhonebook[MAX_PATH ];
    DWORD            dwSubEntry;
    GUID                guidEntry;
    DWORD            dwFlags;
    LUID                luid;
    GUID                guidCorrelationId;
} RASCONN, *PRASCONN;

http://msdn.microsoft.com/en-us/library/windows/desktop/aa377503%28v=vs.85%29.aspx
DWORD RasGetConnectStatus(
    _In_     HRASCONN hrasconn,
    _Inout_  LPRASCONNSTATUS lprasconnstatus
);

http://msdn.microsoft.com/en-us/library/windows/desktop/aa376728%28v=vs.85%29.aspx
typedef struct & _RASCONNSTATUS {
    DWORD                            dwSize;        ; sizeof(RASCONNSTATUS
    RASCONNSTATE                rasconnstate;
    DWORD                            dwError;
    TCHAR                                szDeviceType[RAS_MaxDeviceType + 1];
    TCHAR                                szDeviceName[RAS_MaxDeviceName + 1];
    TCHAR                                szPhoneNumber[RAS_MaxPhoneNumber + 1];
    RASTUNNELENDPOINT    localEndPoint;
    RASTUNNELENDPOINT    remoteEndPoint;
    RASCONNSUBSTATE        rasconnsubstate;
} RASCONNSTATUS;


Viewing all articles
Browse latest Browse all 12506

Trending Articles