Sign in to follow this  
Followers 0
Starstar

Dll Function is not receiving $dwError in console. Why? i could not know.

10 posts in this topic

#1 ·  Posted (edited)

#include <WinAPI.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
Local Const $DNLEN =15

Global Enum $RASCS_OpenPort = 0, $RASCS_PortOpened, $RASCS_ConnectDevice, $RASCS_DeviceConnected, $RASCS_AllDevicesConnected, _
        $RASCS_Authenticate, $RASCS_AuthNotify, $RASCS_AuthRetry, $RASCS_AuthCallback, $RASCS_AuthChangePassword, $RASCS_AuthProject, _
        $RASCS_AuthLinkSpeed, $RASCS_AuthAck, $RASCS_ReAuthenticate, $RASCS_Authenticated, $RASCS_PrepareForCallback, _
        $RASCS_WaitForModemReset, $RASCS_WaitForCallback, $RASCS_Projected, _
        $RASCS_StartAuthentication, _
        $RASCS_CallbackComplete, _
        $RASCS_LogonNetwork, _
        $RASCS_SubEntryConnected, _
        $RASCS_SubEntryDisconnected, _
        $RASCS_ApplySettings, _
        $RASCS_Interactive = 0x1000, _
        $RASCS_RetryAuthentication, _
        $RASCS_CallbackSetByCaller, _
        $RASCS_PasswordExpired, _
        $RASCS_InvokeEapUI, _
        $RASCS_Connected = 0x2000, _
        $RASCS_Disconnected

Func RasDialFunc1($hrasconn, $iMsg, $rasconnstate, $dwError, $dwExtendedError)
 If $dwError Then
        Local $aRet = DllCall("Rasapi32.dll", "dword", "RasGetErrorStringW", "uint", $dwError, "wstr", "", "dword", 256)
        Sleep(100)
        ConsoleWrite("!" & $aRet[2] & @CRLF)

EndIf

    Switch $rasconnstate
        Case $RASCS_OpenPort
            ConsoleWrite("Opening port..." & @CRLF)
        Case $RASCS_PortOpened
            ConsoleWrite("Port Opened..." & @CRLF)
        Case $RASCS_ConnectDevice
            ConsoleWrite("Connecting device..." & @CRLF)

        Case $RASCS_DeviceConnected
            ConsoleWrite("Device connected..." & @CRLF)

        Case $RASCS_AllDevicesConnected
            ConsoleWrite("All devices connected..." & @CRLF)

        Case $RASCS_Authenticate
            ConsoleWrite("Authenticating..." & @CRLF)

        Case $RASCS_AuthNotify
            ConsoleWrite("Authentication notify..." & @CRLF)

        Case $RASCS_AuthRetry
            ConsoleWrite("Retrying authentication..." & @CRLF)

        Case $RASCS_AuthCallback
            ConsoleWrite("Authentication callback..." & @CRLF)

        Case $RASCS_AuthChangePassword
            ConsoleWrite("Change password..." & @CRLF)

        Case $RASCS_AuthProject
            ConsoleWrite("Projection phase started..." & @CRLF)

        Case $RASCS_AuthLinkSpeed
            ConsoleWrite("Negotiating speed..." & @CRLF)

        Case $RASCS_AuthAck
            ConsoleWrite("Authentication acknowledge..." & @CRLF)

        Case $RASCS_ReAuthenticate
            ConsoleWrite("Retrying Authentication..." & @CRLF)

        Case $RASCS_Authenticated
            ConsoleWrite("Authentication complete..." & @CRLF)

        Case $RASCS_PrepareForCallback
            ConsoleWrite("Preparing for callback..." & @CRLF)

        Case $RASCS_WaitForModemReset
            ConsoleWrite("Waiting for modem reset..." & @CRLF)

        Case $RASCS_WaitForCallback
            ConsoleWrite("Waiting for callback..." & @CRLF)

        Case $RASCS_Projected
            ConsoleWrite("Projection completed..." & @CRLF)
        Case $RASCS_StartAuthentication
            ConsoleWrite("Starting authentication..." & @CRLF)

        Case $RASCS_CallbackComplete
            ConsoleWrite("Callback complete..." & @CRLF)

        Case $RASCS_LogonNetwork
            ConsoleWrite("Logon to the network..." & @CRLF)


        Case $RASCS_SubEntryConnected
            ConsoleWrite("Subentry connected..." & @CRLF)

        Case $RASCS_SubEntryDisconnected
            ConsoleWrite("Subentry disconnected..." & @CRLF)

        Case $RASCS_Connected
            ConsoleWrite("Connection completed." & @CRLF)

        Case $RASCS_Disconnected
            ConsoleWrite("Disconnecting..." & @CRLF)


        Case Else
            ConsoleWrite("Unknown Status = " & $rasconnstate  & @CRLF)

    EndSwitch

EndFunc   ;==>RasDialFunc



Global $tagRASCONNSTATUS = "dword dwSize;dword rasconnstate;wchar szDeviceType[" & $RAS_MaxDeviceType & "];wchar szDeviceName[" & $RAS_MaxDeviceName & "];" & _
        "wchar szPhoneNumber[" & $RAS_MaxPhoneNumber & "];dword localEndPoint;byte[16];word[8];dword remoteEndPoint;byte[16];word[8];dword rasconnsubstate"

Global Const $tagRASDIALPARAMS = "dword dwSize;wchar szEntryName["& $RAS_MaxDnsSuffix +1 &"];wchar szPhoneNumber["& $RAS_MaxDeviceName +1 &"];wchar szCallbackNumber["& $RAS_MaxDeviceName +1 & "];wchar szUserName[" & $RAS_MaxDnsSuffix +1 & "];wchar szPassword["& $RAS_MaxDnsSuffix + 1 & "];wchar szDomain["&$DNLEN +1 &"];dword dwSubEntry;ULONG_PTR dwCallbackId;dword dwIfIndex"
Local $tRASDIALPARAMS = DllStructCreate($tagRASDIALPARAMS)
$tRASDIALPARAMS.dwSize = DllStructGetSize($tRASDIALPARAMS)


DllStructSetData($tRASDIALPARAMS, "szEntryName", "DM-LINK")
DllStructSetData($tRASDIALPARAMS, "szPhoneNumber", "")
DllStructSetData($tRASDIALPARAMS, "szCallbackNumber", "")
DllStructSetData($tRASDIALPARAMS, "szUserName", "PPP455")
DllStructSetData($tRASDIALPARAMS, "szPassword", "455")
DllStructSetData($tRASDIALPARAMS, "szDomain", "")

Local $FilePath=@AppDataDir & "\Microsoft\Network\Connections\Pbk\rasphone.pbk"
Local $hHandle = DllCallbackRegister("RasDialFunc1", "none", "HANDLE*;UINT;lparam;wparam;wparam")
Local $iRet = DllCall("Rasapi32.dll", "dword", "RasDialW", "ptr", 0,"wstr",$FilePath, "ptr",DllStructGetPtr($tRASDIALPARAMS), "dword", 1, "ptr", DllCallbackGetPtr($hHandle), "handle*", NULL)
Sleep(150)
MsgBox(0,"Function Return","RasDial : "&$iRet[0])
Sleep(300)
DllCallbackFree($hHandle)

Function is not receiving $dwError. Why? i could not know. Please Help me.

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."

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Don't put Sleep In the Callback.

Your Code is connecting  to rasdial correctly?

 

Saludos 

PD:I lost my USB where I had the example. If I have time. I'll rewrite the example.

Edited by Danyfirex

Share this post


Link to post
Share on other sites

Don't put Sleep In the Callback.

Your Code is connecting  to rasdial correctly?

 

Saludos 

PD:I lost my USB where I had the example. If I have time. I'll rewrite the example.

ok and thanks i shall remove sleep() from dll.


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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

your code dial-up Correctly?

Edit:

my code was base on this take a look. :)

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

your code dial-up Correctly?

Edit:

my code was base on this take a look. :)

Saludos

yes bro i know it is dial -up correctly but whenever some problem etc.. server is not available occurred script was close and dialing modem Jam at connecting.error was not occurred while it was. 

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."

Share this post


Link to post
Share on other sites

You need to create the event. check the status and set the event state. Look the C++ example above.

Saludos

1 person likes this

Share this post


Link to post
Share on other sites

You need to create the event. check the status and set the event state. Look the C++ example above.

Saludos

Thanks for hint........now i am going to trying WINAPI CreateEvent() Function.


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

Share this post


Link to post
Share on other sites

any doubt ask for...

Saludos

Share this post


Link to post
Share on other sites

Global Const $RAS_MaxDeviceType = 16
Global Const $RAS_MaxDeviceName = 128
Global Const $RAS_MaxPhoneNumber = 128


Global $RASCONNSTATUS = "dword dwSize;dword rasconnstate;dword DwError;wchar szDeviceType[" & $RAS_MaxDeviceType +1 & "];wchar szDeviceName[" & $RAS_MaxDeviceName +1 & "];" & _
        "wchar szPhoneNumber[" & $RAS_MaxPhoneNumber +1 & "];dword localEndPoint;byte[16];word[8];dword remoteEndPoint;byte[16];word[8];dword rasconnsubstate"
Local $tRASStatus = DllStructCreate($RASCONNSTATUS)

Local $iRas = DllCall("Rasapi32.dll", "dword", "RasGetConnectStatusW","handle*", "*lphRasConn","ptr",$tRASStatus)

MsgBox(0,"Return",$iRas[0])

i am trying to get rasconnection status but i got error 87 ERROR_INVALID_PARAMETER.


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

Share this post


Link to post
Share on other sites

Your API call is wrong. Should be so:

Local $iRas = DllCall("Rasapi32.dll", "dword", "RasGetConnectStatusW","handle",$yourhandle,"ptr",DllStructGetPtr($tRASStatus))

Remember set the dwSize before the call.

Saludos

1 person likes this

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