I'm trying to inspect a COM object in VB.Net using reflection
More specifically I'm trying to get the element type for a COM array
parameter
I have a vb6 class defined as follows
Option Explicit
Public Function ArrayFunction(dwArray() As Long, _
sArray() As Single, _
dwValue As Long, _
ByVal sValue As Single) As Long
ArrayFunction = 0
End Function
I wrote a vb.net client and added a reference to the dll created from the
above code. This resulted in
the creation of a run-time callable wrapper, Interop.TestObject06.dll, for
the COM object.
The relevant portion of the vb.net client is given below
Dim oAssembly As [Assembly]
Dim oObj As Object
Dim oMethod As MethodInfo
Dim oParameter As ParameterInfo
Dim oParameterAttributes As ParameterAttributes
oAssembly = oAssembly.LoadFrom("Interop.TestObject06.dll")
oObj =
Activator.CreateInstance(oAssembly.GetType("TestObject06.CTestObject06Class"
))
oMethod =
oObj.GetType.GetInterface("_CTestObject06").GetMethod("ArrayFunction")
Console.WriteLine("ArrayFunction Parameters")
For Each oParameter In oMethod.GetParameters
Console.WriteLine(" " + oParameter.Name.ToString + " " + _
oParameter.ParameterType.ToString + " " + _
oParameter.Attributes.ToString)
Next oParameter
The output from the vb.net code follows
ArrayFunction Parameters
dwArray System.Array& In, Out, HasFieldMarshal
sArray System.Array& In, Out, HasFieldMarshal
dwValue System.Int32& In, Out
sValue System.Single In
The data type returned for both dwArray and sArray is System.Array&
I wish to retrieve the element type for each array (ie. int32 for dwArray
and float32 for sArray)
I notice that the HasFieldMarshal attribute is set for both arrays
If I run ildasm on Interop.TestObject06.dll I get the following information
for the ArrayFunction method
.method public hidebysig newslot virtual abstract
instance int32 ArrayFunction([in][out] class
[mscorlib]System.Array& marshal( safearray int32) dwArray,
[in][out] class
[mscorlib]System.Array& marshal( safearray float32) sArray,
[in][out] int32& dwValue,
[in] float32 sValue) runtime managed
internalcall
{
.custom instance void
[mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = (
01 00 00 00 03 60 00 00 ) // .....`..
} // end of method _CTestObject06::ArrayFunction
ildasm can retrieve the element types for dwArray and sArray (int32 and
float32, respectively) so
this information is probably in Interop.TestObject06.dll somewhere.
I wish to know the reflection query that is required to obtain this
information
Thanks in adance for any help
Wayne
Email: ZzWayne...@NRC.cazZ
Note that a leading Zz and trailing zZ have been added to my email address
to reduce spam
Remove the leading Zz and trailing zZ to obtain the proper email address.
microsoft.public.dotnet.framework.interop is a better group for
interop related questions.
>I wrote a vb.net client and added a reference to the dll created from the
>above code. This resulted in
>the creation of a run-time callable wrapper, Interop.TestObject06.dll, for
>the COM object.
>The relevant portion of the vb.net client is given below
When you let VS.NET create an interop assembly for you, or when you
run TlbImp from the command line with the /sysarray option, all array
parameters are imported as a generic System.Array type.
If you instead run TlbImp without the /sysarray option, arrays are
imported strongly typed, like Integer() and Single() for example.
So the easiest solution for you, which would make it a lot easier to
figure out the array type, would be to generate a new interop assembly
with TlbImp.
Mattias
===
Mattias Sjögren (VB MVP)
mattias @ mvps.org
http://www.msjogren.net/dotnet/