We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Pointers in VBScript

prophet001 asked
Medium Priority
Last Modified: 2012-05-11
 I am trying to use a COM object in VBScript to do some cool things to our SFTP server and need a little bit of help. The server offers an API callable through a COM interface and I am trying to use this in VBScript.
Specifically, I am trying to make a call to a function that uses a pointer to a BSTR for an [out] value that it will return.
I create the object without any problems and try to call the function but VBScript stops me. (I think it's VBScript, it might be making it to the COM server idk.)

Here is the prototype for the function:

SVR_GetAttr(LPCTSTR szServerName, LPCTSTR szAttrName, BSTR* pszAttrValue);

and this is how I've tried to call it

Dim attr
obj = 'create object here
obj.SVR_GetAttr "servername", "attrname", attr
^--- fails

Thank you for any help that you can give on this. I'm not even sure if VBScript supports this type or not.If I have to I guess I could go into C# or C++ but I would rather not.

Thank you again,
Watch Question

This line probably caused the problem:

   obj = 'create object here

change is to something like:

   Set obj = CreateObject("your_object_name")



yeah i shouldn't have typed that. I just was trying to not expose the COM object. The COM object is created properly without issue.

Can you try this?

obj.SVR_GetAttr "servername", "attrname", CStr(attr)



well it's not breaking but it's not returning values to the variables either. I used CStr(attr) and the program ran without issue but when i view the contents of the variable it doesn't have anything in it.

There is another function whose prototype is:

SVR_GetAttr2(LPCTSTR szServerName, LPCTSTR szAttrName, BSTR* pszAttrValue, LONG* lError);

and i used this with CLng(errRes) for the last parameter and there was no value in the errRes variable. It seems like the variables aren't being passed as pointers and aren't receiving input from the COM server.
Unlock this solution and get a sample of our free trial.
(No credit card required)



so pretty much it won't work. I don't have access to the source code and can't rewrite it or do any fixing of it.

thank you for finding this sungenwang. I appreciate your help.


You're welcome!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.