cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
rgreen
Level 5

Checking COM array bounds in installscript

I've got some installscript that gets a property value from a COM object (a WMI class) that is a COM array (a COM safearray wrapped in a variant for us old/former C++/COM developers). In VBscript, one would typically call LBound() and UBound() to get the indexing limits for enumerating the array. However, no native support seems to exist for this in installscript. Not knowing how to terminate my array iteration loop, I simply tested for string length == 0 (it's a string array). What is odd, is that this code actually worked on XP, however on Server 2003 it throws an exception as I would've expected. For now, I've simply wrapped the loop in a try-catch to to stop the loop when the array bounds are exceeded. Not pretty. Anyone with a better idea?

I just upgraded from v12 to v2008 yesterday and I thought I saw a page on the product site about COM support enhancements however I can't seem to find it now. Are there COM support enhancements in IS2008 installscript?

Thanks

FYI
I am using the popular "IsGetObj" dll posted to InstallSite for enumerating COM objects that support the IDispatch based object enumeration. This dll does not do Safearray enumeration though. I could see extending it to do so but with my current time constraints I'm not so inclined.
Labels (1)
0 Kudos
(5) Replies
RobertDickau
Flexera Alumni

Perhaps use SizeOf to get the number of elements in an array?

As for the COM-related InstallScript enhancements, please see the InstallShield 2008 release notes; there's a link in the sticky post at the top of this forum.
0 Kudos
Christopher_Pai
Level 16

I've not done this kind of stuff in awhile.... If the collection exposes an Item() method (whatever the correct term is ) you can usually use the upper lower stuff you talk about. The collections that don't, well the IsObj code from InstallSite is what I've used to get everything I've ever needed to work. I'm afraid your into a COM issue that I've never stepped into.
0 Kudos
rgreen
Level 5

A COM safearray, which is how they're known in the C++/COM world, are the underlying datatype for the regular array type in a COM automation language like VB6 or VB script. Since this is really a specialized data structure and not a COM object with callable methods/properties, it is really a different sort of an animal. I guess a language would need specialized support built into it to generate calls to the Windows COM safearray C/C++ APIs to work with this datatype natively. I'm sure that is what VB/VBscript is doing under the covers.

That'd be another nice-to-have for the IS folks to add to installscript for better COM interop. Given all the old legacy COM interfaces / API that installs often need to talk with, I'd think better COM interop should be a higher priority.

Only workaround I see is if anyone would find the time to contribute a COM safearray dll handler to the community. Maybe I should do one if I ever find the time. However, that won't happen in the immediate time frame!
0 Kudos
RobertDickau
Flexera Alumni

Does SizeOf not work?
0 Kudos
rgreen
Level 5

RobertDickau wrote:
Does SizeOf not work?


I'll try to test that if I get a chance. However, this array will almost always have only 1 element in it, but I need to be prepared for additional elements if returned. So I'll need to contrive a special test situation to test it. For now, my try-catch does seem to do the job. I'll definitely post back if I get a chance to test. I'll at least see what sizeof() does with my typical 1 element situation.

Unless you know if the sizeof operator has special logic behind it that detects safearrays and deals with them differently then normal arrays I doubt that it'll work though. I recall that safearrays are laid out in memory totally differently then a simple base pointer to a contiguous block of memory. For example, I think the bounds data for the variable dimension count is indirectly pointed at via a pointer stored 4 bytes before the base pointer for the datatype. Hence the need for all the MS helper APIs to access them correctly.

Thank-you for your prompt replies though.
0 Kudos