Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. VBScript, how to use VT_BSTR?

VBScript, how to use VT_BSTR?

Scheduled Pinned Locked Moved COM
toolscomtestinghelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lucy 0
    wrote on last edited by
    #1

    I am new to COM and VBSCript. I am trying to get an automation function to return a status text string, so when writing script, the tester knows the status of an object under test. This is how I declare and define the function: DISP_FUNCTION(CScriptObject, "GetStatus", GetStatus, VT_BSTR, VTS_BSTR VTS_I4 VTS_BSTR) BSTR CScriptObject::GetStatus(LPCTSTR Item, int ID, LPCTSTR WhichStatus) { return L("test"); } the script is as follows: dim string; string = GetStatus "Item-A", 120, "Dummy" When running it, virtual HRESULT __stdcall OnScriptError(IActiveScriptError *pscriptError) gives me the an error message, saying "string = GetStatus "Item-A", 120, "Dummy"" has error. But running (GetStatus "Item-A", 120, "Dummy") alone is ok. By "ok" I mean the automation function "GetStatus" will be called. Any idea how to have "GetStatus" to return some test string which can be used by VBScript? Thank you very much in advance!

    V 1 Reply Last reply
    0
    • L lucy 0

      I am new to COM and VBSCript. I am trying to get an automation function to return a status text string, so when writing script, the tester knows the status of an object under test. This is how I declare and define the function: DISP_FUNCTION(CScriptObject, "GetStatus", GetStatus, VT_BSTR, VTS_BSTR VTS_I4 VTS_BSTR) BSTR CScriptObject::GetStatus(LPCTSTR Item, int ID, LPCTSTR WhichStatus) { return L("test"); } the script is as follows: dim string; string = GetStatus "Item-A", 120, "Dummy" When running it, virtual HRESULT __stdcall OnScriptError(IActiveScriptError *pscriptError) gives me the an error message, saying "string = GetStatus "Item-A", 120, "Dummy"" has error. But running (GetStatus "Item-A", 120, "Dummy") alone is ok. By "ok" I mean the automation function "GetStatus" will be called. Any idea how to have "GetStatus" to return some test string which can be used by VBScript? Thank you very much in advance!

      V Offline
      V Offline
      Vi2
      wrote on last edited by
      #2

      Due to VB syntax requirement, you should parenthesize the parameters if use the return value: string = GetStatus( "Item-A", 120, "Dummy" ) or Call GetStatus( "Item-A", 120, "Dummy" ) or GetStatus "Item-A", 120, "Dummy" Also L("test") is not valid BSTR. Use SysAllocString etc.

      With best wishes, Vita

      L 2 Replies Last reply
      0
      • V Vi2

        Due to VB syntax requirement, you should parenthesize the parameters if use the return value: string = GetStatus( "Item-A", 120, "Dummy" ) or Call GetStatus( "Item-A", 120, "Dummy" ) or GetStatus "Item-A", 120, "Dummy" Also L("test") is not valid BSTR. Use SysAllocString etc.

        With best wishes, Vita

        L Offline
        L Offline
        lucy 0
        wrote on last edited by
        #3

        got it. Thanks a lot, Vi2!

        1 Reply Last reply
        0
        • V Vi2

          Due to VB syntax requirement, you should parenthesize the parameters if use the return value: string = GetStatus( "Item-A", 120, "Dummy" ) or Call GetStatus( "Item-A", 120, "Dummy" ) or GetStatus "Item-A", 120, "Dummy" Also L("test") is not valid BSTR. Use SysAllocString etc.

          With best wishes, Vita

          L Offline
          L Offline
          lucy 0
          wrote on last edited by
          #4

          hi Vita, more questions. When I use SysAllocString in the "GetStatus" function, where should I call SysFreeString to free up the memory? Will the following script do? ---------- option explicit dim result result = GetStatus ("Item-A", 120, "Dummy") set result = nothing ------------ thanks a lot! - Lucy

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups