locked
Accessing Win32 API in VB script(.VBS files) RRS feed

  • Question

  • I used the win32 API functions in VB Script to find the window handle of a message box using a wrapper dll (dynwrap.dll)

    In the same application I have to get the window text for the message box. I used the getwindowtext API function. In this API function the window caption is stored in string.

    But in VB Script we can use variant data type only. With this variant data type the API function does not return the window caption. It returns only the blank space. The API expects a string buffer to hold the window caption.

    But the same code with a variable declared as string in VBA working fine.

    My question is there any way to declare a variable type in VB script.

    Regards

    Prabhakaran.S

    Wednesday, March 22, 2006 4:35 AM

Answers

  • Per our support engineer:

    According to the following specification, VBScript only has Variant data type.
     
    VBScript has only one data type called a Variant. A Variant is a special kind of data type that can contain different kinds of information, depending on how it is used. Because Variant is the only data type in VBScript, it is also the data type returned by all functions in VBScript.
     
    To use Windows API function in VBScript, we need to create e.g. automation object that VBScript can call. In the automation object, call GetWindowText Function and return the needed information. We can create the automation object using Visual Basic or Visual C++.
     
    For example, the following sample illustrates automation server with MFC using Visual C++.
    INPROC Sample: Demonstrates an In-Process Automation Server Application

    -brenda (ISV Buddy Team)

    Wednesday, April 5, 2006 3:01 PM

All replies

  • Per our support engineer:

    According to the following specification, VBScript only has Variant data type.
     
    VBScript has only one data type called a Variant. A Variant is a special kind of data type that can contain different kinds of information, depending on how it is used. Because Variant is the only data type in VBScript, it is also the data type returned by all functions in VBScript.
     
    To use Windows API function in VBScript, we need to create e.g. automation object that VBScript can call. In the automation object, call GetWindowText Function and return the needed information. We can create the automation object using Visual Basic or Visual C++.
     
    For example, the following sample illustrates automation server with MFC using Visual C++.
    INPROC Sample: Demonstrates an In-Process Automation Server Application

    -brenda (ISV Buddy Team)

    Wednesday, April 5, 2006 3:01 PM
  • Info/Theory:
    ~~~~~~~~~~~
    User32.dll is the source of many of the most common Windows API's, that allow you to
    interact with the operating system at a lower level.

      Following is the code to access Win32 API using VBSCript.
    ---------------------------------------------------------
    ' --------------- Start of Code ------------------------------------------------------------
    Dim excel
    Set excel = CreateObject("Excel.Application")
    Dim strMacro
    strMacro = "CALL('user32', 'MessageBoxA', 'JJCCJ', 0, 'Hello, Win32 API(VBScript) World - My call via User32 dll!', 'Hello, World!', 0)"
    strMacro = Replace( strMacro, "'", """" )
    excel.ExecuteExcel4Macro( strMacro )
    '---------------- End of Code --------------------------------------------------------------

    Copy the above to a notepad & save it as : myMessage.vbs and double click it.

    Expected Result: if you want to see the script in action let me know.

    Thursday, September 27, 2018 1:54 PM