I have the following COM definition, which supposedly takes in a vector of strings.
************** IDL *************************
[id(1), helpstring("method myMethod")]
HRESULT myMethod( [in] VARIANT* bFlags, [out,retval] VARIANT* result);
************** IDL *************************
I Have an example using C++ where the method is called
***************** C++ *******************
Expand|Select|Wrap|Line Numbers
- void
- initComVariantArray( const std::vector<std::string>& inputFlags,
- CComVariant& rOutputFlags )
- throw ( _com_error )
- {
- rOutputFlags.ChangeType( VT_VARIANT );
- CComSafeArray<VARIANT> inputArray( (ULONG) 0 );
- for ( unsigned int i = 0; i < inputFlags.size(); ++i )
- {
- CComVariant comPacsKey;
- CComBSTR tmpString( inputFlags[i].c_str() );
- // The operator= will set automatically the type to VT_BSTR
- comPacsKey = tmpString;
- HRESULT hr = inputArray.Add( comPacsKey );
- if ( FAILED( hr ) )
- {
- throw _com_error( hr );
- }
- }
- // The operator= will add automatically the type VT_ARRAY to the vt
- rOutputFlags = inputArray;
- }
- Main():
- {
- CComVariant vFlags;
- vector<string> vecFlags(); vecFlags.push_back( "flag1" );
- initComVariantArray( vecFlags, vFlags );
- CComVariant vResult = pInteface->myMethod( (&vFlags );
- }
This works great with C++, but i can't get the interface to work in C#. when i import the interface into C#, i get the following definition:
*************** C# ************************
Expand|Select|Wrap|Line Numbers
- myMethod( ref object );
- and calling the method as:
- string [] flags = { "flag1" };
- object objFlag = ( object ) flags;
- myMethod( ref objFlag );
System.Runtime.InteropServices.SEHException: External component has thrown an exception.
*************** C# ************************
If you guys know what im doing wrong here, it would be a lot of help.
Thanks in advance.