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

Problem using a COM dll in Installscript

Hello,

We require to use a COM dll in Installscript. One of the COM functions expects a structure to be passed as an input parameter. In the script, i declare a structure which has exactly the same members as defined in the COM dll.


I initialize the members of the structure and pass the structure as an input argument to the COM dll.
I get the following error:
Error number = -2147024809
Error description = The parameter is incorrect


The structure is declared in the COM dll as follows:
typedef /* [public][public] */ struct __MIDL___MIDL_itf_NetIQXMLParser_0000_0000_0001
{
BSTR Name;
BSTR Machine;
BSTR Version;
BSTR HotFix;
BSTR DateApplied;
int Status;
} ComponentStruct;


My structure in installscript is as follows:
typedef ComponentStruct1
begin
STRING Name[1024];
STRING Machine[1024];
STRING Version[1024];
STRING HotFix[1024];
STRING DateApplied[1024];
int Status;
end;

Where am i going wrong?

Help please. I am stuck on this from teh past few days and i have to finish this in a day or two.
Labels (1)
0 Kudos
(3) Replies
joshstechnij
Level 10 Flexeran
Level 10 Flexeran

The BSTR type is typically defined in C/C++ as:
typedef OLECHAR* BSTR; // OLECHAR is usually WCHAR/wchar_t

The structure definition should therefore be using POINTER as the type for the string members of the structure.

Unfortunately though, if these string members need to be initialized through script (by setting them to the address of a string variable), the InstallScript engine will convert the internal string variable value from a Unicode string to an ANSI version of that string. Since the COM interface is expecting a structure with BSTR strings (which are Unicode), and the InstallScript engine will pass the strings as ANSI, the string values will look corrupted from the COM DLL interface. The only way currently to work around this would be define an interface that accepted ANSI string pointers, or define an interface that does not use a structure (the InstallScript engine will then directly pass strings correctly). We are looking to address this limitation in a future release of the product.
0 Kudos
kirann_hegde
Level 5

Is this a limitation in InstallShield 2009?

However when i read the documentation for using COM in Installscript, the documentation clearly statest that you can directly pass a structure. There is no limitation which has been mentioned. Do we have a KB article or is this mentioned anywhere?
0 Kudos
joshstechnij
Level 10 Flexeran
Level 10 Flexeran

The invalid parameter exception you are seeing is due to the InstallScript engine attempting to pass an IDispatch pointer to an interface method that is defined as taking a custom user data type (structure). The error comes from an IDispatch::Invoke call the engine makes to call the requested COM interface/method.

There are a few limitations on the COM support InstallScript implements. Here are a few things to note about structures in InstallScript:

- Only automation compatible types can be used on COM interfaces called by InstallScript. The InstallScript engine does not support user defined types.
- InstallScript structures can be passed by value to a COM interface. One thing to note however, is passing by value actually passes an object (IDispatch pointer) to the interface being called (see link below). In order to access structure members, they can only be accessed through IDispatch.
- InstallScript structures can be passed by reference to C-style interfaces, allowing direct access to the structure information.
- InstallScript structures currently only support storing ANSI strings or pointers to ANSI strings (when WSTRING support was added, it was not extended to structure member support).

These limitations aren't documented to my knowledge since they are not encountered very often.

More information on how structures work in InstallScript can be found in the following article:
http://installsite.org/files/IS6_Structures.htm
0 Kudos