VBScript, how to use VT_BSTR?
-
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!
-
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!
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
-
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
-
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
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