Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you call Windows API's from VB Script?

Status
Not open for further replies.

bakerm

Programmer
Apr 25, 2000
53
US
I am trying to use functionality contained within th User32.dll. Can this be done with VB Script?

Thanks in advance for any information!
 
strictly speaking no.
there are some third party tools to do it, cant recall the name tsuji has done some posts on it,
you can use rundll32.exe or something like that its called.

the dll thing is misleading though,
 
You can experiment with custom components. One that I have tried on rare occasion is dynwrap. You can still get it at G Born's site wsh bazzaar.
It is not easy to use and very restrictive mainly due the datatypes and low-level access script can(not) handle. Note also that it is by no means unique. I do have posted some not immediately trivial tiny use, always for learning and experience on territory not commonly visited by scripter.

However, you can hack into vba using office application. Hence, there you are gaining more freedom as the datatyping is much warmly received.

Here is an example calling kernal function not commonly available to scripting. It illustrates the mechanism of how to do it.
[tt]
dim scode, oxl, owb, omod, idata

scode="declare function GetACP Lib ""kernel32"" () as integer" & vbcrlf
scode=scode & "function acp()" & vbcrlf
scode=scode & "acp=GetACP" & vbcrlf
scode=scode & "end function"

on error resume next
set oxl=createobject("excel.application")
oxl.visible=false
set owb=oxl.workbooks.add
set omod=owb.vbproject.vbcomponents.add(1)
omod.codemodule.addfromstring scode
idata=oxl.run("acp")
set omod=nothing
owb.saved=true
oxl.quit
set oxl=nothing
on error goto 0

wscript.echo "Default/Current ANSI code-page identifier for the system : " & idata
wscript.quit
[/tt]
 
...you can hack into vba using office application...
[rofl]
Oh that is a very cute trick!

PS: If you have VB6 you could just make a simple ActiveX DLL project to call your specific Win32 function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top