Reflection in COM

  • Thread starter Thread starter Mark Schmidt
  • Start date Start date
M

Mark Schmidt

Here's what I need to do:

Given a string representing a COM progID, instantiate the COM object (I know
how to do that). The next step is to call a set method for a property. The
catch is that the property is sent to me as a string and I need to
convert/coerce/change the type of the passed in parameter to the type of the
COM property. Here's what I've tried:

// creates the COM object from its type found via GetTypeFromProgID (this
works fine)
public bool CreateLUIControl( string progID )
{
this.progID = progID;
pluginType = Type.GetTypeFromProgID(progID);
if( pluginType == null )
{
return false;
}
plugin = (ILUIPlugin) Activator.CreateInstance(pluginType);
if( plugin == null )
{
return false;
}
return true;
}

// attempts to set a property on the COM object given the property name
// NOTE: GetMethods never returns any MethodInfo objects which is the
problem
// the pluginType variable's type says System.__ComObject
public object SetProperty( string property, string value )
{
foreach (MethodInfo pInfo in pluginType.GetMethods(
BindingFlags.Public ) )
{
MessageBox.Show(pInfo.Name);
}

return null;
}
 
Mark,
Given a string representing a COM progID, instantiate the COM object (I know
how to do that). The next step is to call a set method for a property. The
catch is that the property is sent to me as a string and I need to
convert/coerce/change the type of the passed in parameter to the type of the
COM property. Here's what I've tried:

Reflection only understands managed metadata, not COM. You'll have to
use ITypeInfo and related COM interfaces to retrieve information about
the property.



Mattias
 
I was afraid you were going to say that.

-Mark

Mattias Sjögren said:
Mark,


Reflection only understands managed metadata, not COM. You'll have to
use ITypeInfo and related COM interfaces to retrieve information about
the property.



Mattias
 
Back
Top