1

We received this 'new' COM object dll (why not .NET is beyond me) from the vendor for one of our business applications a few days back. Due to the extreme lack of documentation (no example or instructions on how to integrate the COM object to the existing system), we've been struggling to integrate it into our existing infrastructure.

Here I am trying to use Powershell to access a method called 'API' in the COM object class and read the results returned by it. The method is used to call the various APIs depending on what we want to do. The parameters for any given API are passed in as an object array. The returned value is stored in a custom type called colGeneric, which is essentially an array with key/value pairs (with the custom type clsGeneric). In this case it returns two pairs - pb_result and pb_resulttext.

$comClass = new-object -comObject VendorCOM.VendorClass
$APIName = "SomeAPI"
$ArrayOfParamsNeededByAPI = 12345, "ABC", "2011-08-01"

$resultSet = $comClass.API([REF] $APIName, [REF] $ArrayOfParamsNeededByAPI)

$resultText = $resultSet.Item([ref] "pb_resulttext")

When I try to print out $clsGenObjResultText, it shows up as System.__ComObject. I know it is a string, but attempts to convert to a string has failed so far. Here is one thing I've tried:

[System.Convert]::ToString($resultText)

It doesn't work as it still returns System.__ComObject. Not sure if I am making sense here, but I just need the result text in string form.

UPDATE Thanks to the diligent people on this website, the correct solution to the above issue is to replace the last statement in the code snippet with:

$resultText = $resultSet.Item([ref] "pb_resulttext").Value

2 Answers 2

3

To me it seems you're trying to fetch the COM-object item with that call. Could be that you just need to use COM to get the property, have you tried $resultText = $resultSet.pb_resulttext?

Otherwise, I'd use the good ol'e Get-Member on $resultSet (and maybe $resultText)

Sign up to request clarification or add additional context in comments.

3 Comments

$resultText = $resultSet.pb_resulttext returned nothing unfortunately. However, using get-member on $resultText (get-member -inputobject $resultText) gave me a list of all the properties on the Com object, among them a member called <Variant Value () {get} {set} {set by ref}>. Hmmm I thought.. interesting.. so I proceeded to replace the last statement in the code snippet with $resultText = $resultSet.Item([ref] "pb_resulttext").Value And a write-host revealed the expected string value!!!! Thank you!
Nice to be able to help :) Just out of curiosity, what does $resultSet | Get-Member return?
Same as get-member -inputobject $resultSet TypeName: System.__ComObject#{'prod_id'} Name MemberType Definition ---- ---------- ---------- DataType Property string DataType () {get} {set} Field Property string Field () {get} {set} ParamType Property string ParamType () {get} {set} Value Property Variant Value () {get} {set} {set by ref}
0

You'll probably need to know the result object's interface to get the value you want. Try using OleView.exe from the Windows SDK to explore the interfaces of the library, including those of colGeneric and clsGeneric. That should give you the key piece of information about the type that Item() actually returns.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.