mr_unreliable
Mon Sep 11 12:40:05 CDT 2006
hi Axel,
When I am referring to "call api's" below, that means calling the
system functions embedded in the system dll's -- such as user32.
If you are courageous enough, or foolhardy enough, to call api's
from script, then you have two options.
Option 1: use a third-party control (such as DynaWrap), or one that
you write yourself.
This code will "find" the window you want, and return a handle,
using dynawrap:
-- <snip> --
Function FindWindow(sClass, sCaption)
Set oDW = nothing ' clear any previous instance
Set oDW = CreateObject("DynamicWrapper") ' start over...
' register (declare) this flavor of api call...
oDW.Register "USER32.DLL", "FindWindowA", "i=ss", "f=s", "r=h"
FindWindow = oDW.FindWindowA(CStr(sClass), CStr(sCaption))
End Function
-- </snip> --
Option 2: use "autoitX", another third-party control. AutoitX
does not permit calling api's directly but it will do what you want.
That's because certain commonly used api's are built into the
autoitX control as methods. For example, to get back the handle
of a specified window. See the "WinGetHandle" function.
http://www.autoitscript.com/autoit3/
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
--- <DynaWrap Boilerplate> ---
It is possible to declare-and-call an api from script,
but you must use a third-party control to do so,
or else write one yourself.
It has already been correctly pointed out that there
is no api-capability in "pure" script.
If you are willing to use a third-party control, then
one such control, called "DynaWrap", can be found on
Guenter Born's website (note: Guenter refers to it as
"DynaCall"). Here is the link to it:
http://people.freenet.de/gborn/WSHBazaar/WSHDynaCall.htm
On that page you will find a download for the control,
plus some code samples.
Note: you may find additional sample code by searching
the archives of the wsh and vbscript ng's.
Note also: DynaWrap does have its limitations. There are
certain things it can't do. For example, you can't call
api's which take typedefs as parameters, and you can't call
api's "by ordinal". But it will work for most of the
"usual suspects".
And finally, DynaWrap doesn't work entirely as advertised.
For example, it is supposed to allow for the declaration of
several api definitions in one instance of itself. I could
never get that to work (in win9x). You will need a new
instance of DynaWrap for every api, or else re-instantiate
the object for every api. Someday I'm going to learn enough
c++ to fix that...
--- </DynaWrap Boilerplate> ---
Axel Gallus wrote:
> Is there a way, to use a user32.dll function over Scripting Host in
> Visual basic Script?
>
> Greeting
>
> A.Gallus
>
>
>