CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2001
    Location
    Israel
    Posts
    116

    VBScript and API

    Hi
    How can i declare an api function in vbscript?
    this is in VB:

    Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    How can i use this function (and others) in VBScript?

    Thanks
    Limor


  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: VBScript and API

    Why don't you give it a try... looks like the hard work is done.


  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: VBScript and API

    You cannot use API functions from VBScript directly. There are a bunch of reasons I could come up with why this isn't possible (like the Declare statement simply doesn't exist in VBScript), but the bottom line is that you can't.

    What you can do, is create a class that can do that (written in VB), and create an instance of that class in VBScript. Something like this:


    'Class1
    Declare Function ShellExecute ...

    public Sub DoShellExecute(strFile)
    ShellExecute strFile, ...
    End Sub

    ' VBScript
    Dim obj
    set obj = CreateObject("Project1.Class1")
    obj.DoShellExecute("c:\my documents\document1.doc")



    Of course, it will be required to registe the class on the machine running the VBScript

    Tom Cannaerts
    [email protected]
    Moderator on http://www.vbcodelibrary.co.uk/board

    A bottomless pit, I'm sure it came with the place, who would dig one on purpose?
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured