Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Reflection and COM

Reply
Thread Tools

Reflection and COM

 
 
Alan Seunarayan
Guest
Posts: n/a
 
      01-14-2004
Hello all,
I am developing a component that uses late-binding to automate Word (as targets have differing versions) and I have created an instance of Word.Application. What I wish to do is to find out the details of the object that I am creating via reflection. At the moment I am creating the Word COM as follows....

Dim oWordX as object = Activator.CreateInstance(Type.CreateFromProgID("Wo rd.Application"))

Can anyone help?


Cheers,

Alan S.
 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      01-14-2004
Alan,

Reflection only understands managed metadata, not COM type info. So
you'll have to reflect on types in an interop assembly for that to
work.

COM type info can be read with (UCOM)ITypeInfo and related
interfaces (in System.Runtime.InteropServices).



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
 
 
 
Alan Seunarayan
Guest
Posts: n/a
 
      01-14-2004
thanks for the reply, is there any chance of some example code please?

"Mattias Sjögren" <(E-Mail Removed)> wrote in message
news:u7$(E-Mail Removed)...
> Alan,
>
> Reflection only understands managed metadata, not COM type info. So
> you'll have to reflect on types in an interop assembly for that to
> work.
>
> COM type info can be read with (UCOM)ITypeInfo and related
> interfaces (in System.Runtime.InteropServices).
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.



 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      01-14-2004
Alan,

>thanks for the reply, is there any chance of some example code please?


Here's some code that prints all names of proporties and methods on
the Word Application object. Error handling excluded for brevity.

<ComImport, Guid("00020400-0000-0000-C000-000000000046"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )> _
Interface IDispatch
Function GetTypeInfoCount() As Integer
Function GetTypeInfo(iTInfo As Integer, lcid As Integer) As
UCOMITypeInfo
Sub _GetIDsOfNames()
Sub _Invoke()
End Interface

Class Test

Shared SUb Main()
Dim t as Type = Type.GetTypeFromProgID("Word.Application")
Dim word As Object = Activator.CreateInstance(t)
Dim disp As IDispatch = DirectCast(word, IDispatch)
If disp.GetTypeInfoCount() = 1 Then
Dim ti As UCOMITypeInfo = disp.GetTypeInfo(0, 0)
Dim pti As IntPtr
ti.GetTypeAttr(pti)
Dim ta As TYPEATTR = DirectCast( _
Marshal.PtrToStructure(pti, GetType(TYPEATTR)), TYPEATTR)
Dim funcs As Integer = ta.CFuncs
ti.ReleaseTypeAttr(pti)
For i As Integer = 0 To funcs - 1
Dim pfd As IntPtr
ti.GetFuncDesc(i, pfd)
Dim fd As FUNCDESC = DirectCast( _
Marshal.PtrToStructure(pfd, GetType(FUNCDESC)), FUNCDESC)
Dim names(0) As String
Dim returned As Integer
ti.GetNames(fd.Memid, names, names.Length, returned)
Console.WriteLine(names(0))
ti.ReleaseFuncDesc(pfd)
Next
End If
Marshal.ReleaseComObject( word )
End Sub
End Class



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Medium Level Trust and Reflection Paul Hatcher ASP .Net 0 02-25-2005 02:12 PM
Type Reflection and Code Directory Andrew Feldman ASP .Net 2 12-20-2004 04:08 PM
ASP.NET 2.0 (beta) and Reflection deja.com@joel.net ASP .Net 2 11-04-2004 04:19 AM
Re: Reflection and SqlConnection WebDevHokie ASP .Net 0 07-10-2003 06:38 PM
Re: Reflection and SqlConnection WebDevHokie ASP .Net 0 07-10-2003 06:33 PM



Advertisments