Jump to content

Would this dll call work?


Recommended Posts

I'm new to DLLCALLs because I have never had a use for them before. I made this test with one of the few calls I knew, can anyone tell me if it works?

DllOpen("Kernel32.dll")
While 1
    If DllCall("Kernel32.dll", "int", "IsDebuggerPresent") = 1 then ExitLoop
    If @error then ExitLoop
    Sleep(1)
WEnd
DllClose("Kernel32.dll")
Link to comment
Share on other sites

I'm new to DLLCALLs because I have never had a use for them before. I made this test with one of the few calls I knew, can anyone tell me if it works?

DllOpen("Kernel32.dll")
While 1
    If DllCall("Kernel32.dll", "int", "IsDebuggerPresent") = 1 then ExitLoop
    If @error then ExitLoop
    Sleep(1)
WEnd
DllClose("Kernel32.dll")
should work (exept for the DllOpen/DllClose part). See: http://msdn.microsoft.com/library/default....ggerpresent.asp

You should read the help file section for DllOpen(). That function returns a handle, which can be used by DllCall() and must be used by DllClose().

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

DLLCall returns an array, where [0] is the return value of the function call

Ups, I overlooked that. You're of course right !!

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

If the current process is running in the context of a debugger, the return value is nonzero.

If the current process is not running in the context of a debugger, the return value is zero.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

If the current process is running in the context of a debugger, the return value is nonzero.

If the current process is not running in the context of a debugger, the return value is zero.

argh.... I need some sleep .... B)

@killaz219: You can only test if the return value is nonzero, as you cannot expect it to be 1 (see first statement above).

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

So it would be this right?

$dll = DllOpen("Kernel32.dll")
While 1
    $dll2 = DllCall($dll, "int", "IsDebuggerPresent")
    If @error then ExitLoop
    If $dll2[0] <> 0 Then ExitLoop
    Sleep(1)
WEnd
DllClose($dll)
Edited by killaz219
Link to comment
Share on other sites

So it would be this right?

If @error then ExitLoop
actually your error handling is not O.K. You treat a general DllCall error (@error is set) in the same way as if your program is beeing debugged. I guess that could cause problems...

EDIT: And the sleep() could be a bit longer ...

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

actually your error handling is not O.K. You treat a general DllCall error (@error is set) in the same way as if your program is beeing debugged. I guess that could cause problems...

Cheers

Kurt

Yep, getting late, @error should only be set if the dllcall failed, if that doesn't fail then you need to check your return value.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

When you're only performing a single DLLCall() on any DLL, you don't need to open and close it. You can have this done automatically during the call and can therefore use:

Local $Ret = DLLCall('Kernel32.dll', 'Int', 'IsDebuggerPresent')

instead of:

Local $DLL = DLLOpen('Kernel32.dll')
Local $Ret = DLLCall($DLL, 'Int', 'IsDebuggerPresent')
DLLClose($DLL)
Link to comment
Share on other sites

When you're only performing a single DLLCall() on any DLL, you don't need to open and close it. You can have this done automatically during the call and can therefore use:

Local $Ret = DLLCall('Kernel32.dll', 'Int', 'IsDebuggerPresent')

instead of:

Local $DLL = DLLOpen('Kernel32.dll')
Local $Ret = DLLCall($DLL, 'Int', 'IsDebuggerPresent')
DLLClose($DLL)
But I had the call in a loop, wouldn't it have to keep opening and closing it after every call if I didn't use DllOpen and DllClose?
Link to comment
Share on other sites

If you're using it in a loop, that is the way to do it (or if you're calling multiple functions from the same DLL).

Local $DLL = DLLOpen('Kernel32.dll'), $Ret
Do
     $Ret = DLLCall($DLL, 'Int', 'IsDebuggerPresent')
Until $Ret[0];Do...Until there is something in $Ret[0]
 ;Until Not $Ret[0];Do...Until $Ret[0] = 0
DLLClose($DLL)

B)

Edited by MSLx Fanboy

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
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...