How can I know the object type of an smartFrame2d embed or linked object

 

Hello

 

 

I have to do some updating on smartFrame2d embeded objects but I am not able to know what type of information is embeded in the object (excel, word, image, txt file).

 

How can I get the type of the object embed (something like the "show interface name" in solid edge spy will be fine or is there any other way to know the object type)

 

 

Thanks in advance

 

 

Posted by: Xabi Bikuna Losada
Post date: 3/25/2011 3:33:10 AM

2 REPLIES

RE: How can I know the object type of an smartFrame2d embed or linked object

Did you try the ObjectType property, which returns a string of your object's type?

 

Posted by: Martin Bernhard
Post date: 3/25/2011 5:00:29 AM

RE: How can I know the object type of an smartFrame2d embed or linked object

 

Objecttype parameters is empty so it can't be used

 

Anyway I found some jasonnewell.net code in this page

 

http://www.ureader.com/msg/14312747.aspx

 

I thnik this is part of the used in solidedge spy to get the com structure. I wanted it in VB.NET so I translated it and it works great so i can do what I was thinking.....

 

 

Althoug I found it in another page, thanks Jason

 

How to use ite

 

 

      objSheet = objDraft.ActiveSheet

      objSFrames2D = objSheet.SmartFrames2d

      For Each objSFrame2D In objSFrames2D

        Dim o As Object = objSFrame2D.Object

 

        If (Marshal.IsComObject(o)) Then

          Dim comObject1 As ComObject = Nothing

          Dim comObject As ComObject = New ComObject(o)

          Dim propertyNames As String() = comObject.GetPropertyNames()

          Dim prop As Object = Nothing

          Dim propertyName As String

          For Each propertyName In propertyNames

            prop = comObject.WrappedComObject.GetType().InvokeMember(propertyName, _

            System.Reflection.BindingFlags.GetProperty, Nothing, _

            comObject.WrappedComObject, Nothing)

            If (prop IsNot Nothing AndAlso Marshal.IsComObject(prop)) Then

              comObject1 = New ComObject(prop)

            End If

          Next

        End If

 

 

 

If someone whats the code here it is (3 Vb.NET files):

 

 

 

 

 

ComObject.vb

---------------

 

Imports System

Imports System.Collections.Generic

Imports System.Runtime.InteropServices

Imports System.Runtime.InteropServices.ComTypes

Imports System.Text

 

 

Public Class ComObject : Implements IDisposable

  Private _object As Object

  Private _dispatch As IDispatch

  Private _pTypeAttr As IntPtr = IntPtr.Zero

  Private _typeInfo As System.Runtime.InteropServices.ComTypes.ITypeInfo

  Private _typeName As String

  Private _typeDescription As String

  Private _typeHelpFile As String

  Private _typeHelpContext As Integer

  Private _comTypeLibrary As ComTypeLibrary

 

  Public Sub New(ByVal comObject As Object)

 

    Dim ppTLB As System.Runtime.InteropServices.ComTypes.ITypeLib = Nothing

    Dim pIndex As Integer = 0

 

    _dispatch = CType(comObject, IDispatch)

 

    If (_dispatch IsNot Nothing) Then

      _object = comObject

      _typeInfo = _dispatch.GetTypeInfo(0, 0)

      _typeInfo.GetTypeAttr(_pTypeAttr)

      _typeInfo.GetDocumentation(-1, _typeName, _typeDescription, _typeHelpContext, _typeHelpFile)

      _typeInfo.GetContainingTypeLib(ppTLB, pIndex)

      _comTypeLibrary = New ComTypeLibrary(ppTLB)

    Else

      Throw New InvalidComObjectException()

    End If

  End Sub

 

  Protected Overrides Sub Finalize()

    Dispose()

  End Sub

 

 

  Public Sub Dispose() Implements IDisposable.Dispose

 

    Try

      If (_typeInfo IsNot Nothing) Then

        _typeInfo.ReleaseTypeAttr(_pTypeAttr)

      End If

 

      If (_object IsNot Nothing) Then

        Marshal.ReleaseComObject(_object)

        _object = Nothing

      End If

 

      If (_dispatch IsNot Nothing) Then

        Marshal.ReleaseComObject(_dispatch)

        _dispatch = Nothing

      End If

 

    Catch ex As Exception

 

    End Try

  End Sub

 

  Public Function GetPropertyNames() As String()

 

    Dim list As System.Collections.ArrayList = New System.Collections.ArrayList()

 

    Try

      For i As Integer = 0 To TypeAttr.cFuncs - 1

        Dim pFuncDesc As IntPtr = IntPtr.Zero

        Dim funcDesc As System.Runtime.InteropServices.ComTypes.FUNCDESC '() ????

        Dim strName As String = ""

        Dim strDocString As String = ""

        Dim strHelpFile As String = ""

        Dim dwHelpContext As Integer

 

        _typeInfo.GetFuncDesc(i, pFuncDesc)

        funcDesc = Marshal.PtrToStructure(pFuncDesc, GetType(System.Runtime.InteropServices.ComTypes.FUNCDESC))

 

        Select Case funcDesc.invkind

          Case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYGET

            _typeInfo.GetDocumentation(funcDesc.memid, strName, strDocString, dwHelpContext, strHelpFile)

            list.Add(strName)

        End Select

 

      Next

 

    Catch ex As Exception

      Throw ex

    End Try

 

    GetPropertyNames = list.ToArray(GetType(String))

  End Function

 

  Public ReadOnly Property TypeName() As String

    Get

      TypeName = _typeName

    End Get

  End Property

 

  Public ReadOnly Property TypeFullName() As String

    Get

      TypeFullName = ComTypeLibrary.Name + "." + _typeName

    End Get

  End Property

 

  Public ReadOnly Property TypeDescription() As String

    Get

      TypeDescription = _typeDescription

    End Get

  End Property

 

  Public ReadOnly Property TypeHelpContext() As String

    Get

      TypeHelpContext = _typeHelpContext

    End Get

  End Property

 

  Public ReadOnly Property TypeHelpFile() As String

    Get

      TypeHelpFile = _typeHelpFile

    End Get

  End Property

 

  Public ReadOnly Property WrappedComObject() As Object

    Get

      WrappedComObject = _dispatch

    End Get

  End Property

 

  Public ReadOnly Property ComTypeLibrary() As ComTypeLibrary

    Get

      ComTypeLibrary = _comTypeLibrary

    End Get

  End Property

 

  Public ReadOnly Property TypeAttr() As System.Runtime.InteropServices.ComTypes.TYPEATTR

    Get

      TypeAttr = Marshal.PtrToStructure(_pTypeAttr, GetType(System.Runtime.InteropServices.ComTypes.TYPEATTR))

    End Get

  End Property

 

  Public ReadOnly Property TypeVersion() As String

    Get

      Dim version As String = String.Empty

      Try

        version = TypeAttr.wMajorVerNum.ToString() + "." + TypeAttr.wMinorVerNum.ToString()

      Catch ex As Exception

 

      End Try

 

      TypeVersion = Version

 

    End Get

  End Property

 

End Class

 

 

 

 

 

 

 

 

ComTypeLibrary.vb

-------------------

 

Imports System

Imports System.Collections.Generic

Imports System.IO

Imports System.Reflection

Imports System.Reflection.Emit

Imports System.Runtime.InteropServices

Imports System.Runtime.InteropServices.ComTypes

Imports System.Text

 

Public Class ComTypeLibrary

 

  Private _typeLib As System.Runtime.InteropServices.ComTypes.ITypeLib

  Private _pTypeLibAttr As IntPtr = IntPtr.Zero

  Private _Name As String

  Private _Description As String

  Private _HelpFile As String

  Private _HelpContext As Integer

 

  Public Sub New(ByVal typeLib As System.Runtime.InteropServices.ComTypes.ITypeLib)

    _typeLib = typeLib

    _typeLib.GetLibAttr(_pTypeLibAttr)

    _typeLib.GetDocumentation(-1, _Name, _Description, _HelpContext, _HelpFile)

  End Sub

 

  Public ReadOnly Property Name() As String

    Get

      Name = _Name

    End Get

  End Property

 

  Public ReadOnly Property Description() As String

    Get

      Description = _Description

    End Get

  End Property

 

  Public ReadOnly Property HelpContext() As Integer

    Get

      HelpContext = _HelpContext

    End Get

  End Property

 

  Public ReadOnly Property HelpFile() As Integer

    Get

      HelpFile = _HelpFile

    End Get

  End Property

 

  Public ReadOnly Property TypeLibAttr() As System.Runtime.InteropServices.ComTypes.TYPELIBATTR

    Get

      TypeLibAttr = Marshal.PtrToStructure(_pTypeLibAttr, GetType(System.Runtime.InteropServices.ComTypes.TYPELIBATTR))

    End Get

  End Property

 

  Public ReadOnly Property TypeLibVersion() As String

    Get

      Dim version As String = String.Empty

 

      Try

        Version = TypeLibAttr.wMajorVerNum.ToString() + "." + TypeLibAttr.wMinorVerNum.ToString()

 

      Catch ex As Exception

 

      End Try

 

      TypeLibVersion = version

    End Get

  End Property

 

  Public ReadOnly Property Version() As Version

    Get

      Version = New Version(TypeLibAttr.wMajorVerNum, TypeLibAttr.wMinorVerNum, 0, 0)

    End Get

  End Property

 

  Public Overrides Function GetHashCode() As Integer

    GetHashCode = TypeLibAttr.guid.GetHashCode() + TypeLibAttr.wMajorVerNum.GetHashCode() + TypeLibAttr.wMinorVerNum.GetHashCode()

  End Function

 

  Public Overrides Function Equals(ByVal obj As Object) As Boolean

    Dim comTypeLibrary As ComTypeLibrary = CType(obj, ComTypeLibrary)

 

    If (comTypeLibrary IsNot Nothing) Then

      If (TypeLibAttr.guid.Equals(comTypeLibrary.TypeLibAttr.guid)) Then

        If (TypeLibAttr.wMajorVerNum.Equals(comTypeLibrary.TypeLibAttr.wMajorVerNum)) Then

          If (TypeLibAttr.wMinorVerNum.Equals(comTypeLibrary.TypeLibAttr.wMinorVerNum)) Then

            Equals = True

            Exit Function

          End If

        End If

      End If

      Equals = MyBase.Equals(obj)

    Else

      Equals = MyBase.Equals(obj)

    End If

 

  End Function

 

  Public Overrides Function ToString() As String

    ToString = Name + " - " + Description

  End Function

 

End Class

 

 

 

 

 

 

IDispatch.vb

-------------

 

Imports System

Imports System.Collections.Generic

Imports System.Runtime.InteropServices

Imports System.Text

 

_

Public Interface IDispatch

  Function GetTypeInfoCount() As Integer

 

  Function GetTypeInfo( ByVal iTInfo As Integer, _

                        ByVal lcid As Integer) As System.Runtime.InteropServices.ComTypes.ITypeInfo

 

  '

  Function GetIDsOfNames(ByRef riid As Guid, _

                         ByVal rgsNames As String(), ByVal cNames As Integer, ByVal lcid As Integer, _

                         ByVal rgDispId As Integer()) As Integer

 

  '

  Function Invoke(ByVal dispIdMember As Integer, ByRef riid As Guid, _

ByVal lcid As Integer,  ByVal dwFlags As Integer, _

ByRef pDispParams As System.Runtime.InteropServices.ComTypes.DISPPARAMS, _

ByVal pVarResult As Object(), _

ByRef pExcepInfo As System.Runtime.InteropServices.ComTypes.EXCEPINFO, _

ByVal pArgErr As IntPtr()) As Integer

 

End Interface

 

 

Posted by: Xabi Bikuna Losada
Post date: 3/25/2011 8:00:12 AM