+ Reply to Thread
Results 1 to 6 of 6

Thread: Getting the real COM class name

  1. #1
    Jens Haffner
    Join Date
    Jun 2010
    Posts
    13
    Points
    0
    Answers Provided
    0


    0

    Default Getting the real COM class name

    This problem really puzzles me...
    I’d like to get the ArcObjects CoClass name behind the interface pointer, which I have.
    If I’ve got an IFeature pointer, I’d like to know whether it’s in fact a Feature object or perhaps a ComplexEdgeFeature or something else.
    No matter what I try, I don’t get the right name…

  2. #2
    Ken Buja

    Join Date
    Jan 2010
    Posts
    1,212
    Points
    874
    Answers Provided
    151


    0

    Default Re: Getting the real COM class name

    Have you tried something like this (in VB.NET)

    Code:
    If TypeOf IFeature Is IComplexEdgeFeature Then
      
    End If
    Ken Buja
    Silver Spring, MD

  3. #3
    Neil Clemmons

    Join Date
    Apr 2010
    Posts
    894
    Points
    570
    Answers Provided
    94


    0

    Default Re: Getting the real COM class name

    As Ken mentioned you can usually use TypeOf and test for a particular interface that will identify the underlying class. In .NET you can also use the GetType method and check the FullName property. This will give you the fully qualified class name.

    Code:
    Dim layer As IFeatureLayer = New FeatureLayer
                    Dim s As String = layer.GetType.FullName
    Neil Clemmons
    Geographic Information Services, Inc.
    http://www.gisinc.com

    Check out our blog:
    http://blog.gisinc.com

  4. #4
    Jens Haffner
    Join Date
    Jun 2010
    Posts
    13
    Points
    0
    Answers Provided
    0


    0

    Default Re: Getting the real COM class name

    Ken, you are absolutely right, it is possible to check it this way:
    Quote Originally Posted by kenbuja View Post
    Code:
    If TypeOf IFeature Is IComplexEdgeFeature Then
    End If
    But I've learned, that in some cases it's difficult to pick an interface that is unique for a particular COM class.

  5. #5
    Jens Haffner
    Join Date
    Jun 2010
    Posts
    13
    Points
    0
    Answers Provided
    0


    0

    Default Re: Getting the real COM class name

    Neil, perhaps I'm doing somthing wrong here, cause I've tried this:
    Code:
    IWorkspace pWorkspace = EsriDatabase.FileGdbWorkspaceFromPath("WhatEver.gdb");
    Console.WriteLine(pWorkspace.GetType().FullName);
    This code outputs "System.__ComObject" no matter which interface or class I use.
    Last edited by haffner; 07-20-2012 at 01:37 AM.

  6. #6
    Swapna Shetty
    Join Date
    Jun 2011
    Posts
    146
    Points
    43
    Answers Provided
    6


    0

    Default Re: Getting the real COM class name

    its a little tricky to get the type of com object. you may have to iterate through all the types and compare the object pointer with array of pointers returned by the com object. Below is the code to accomplish this. Hope this helps

    Code:
     IntPtr iunkwn = Marshal.GetIUnknownForObject(pWorkspace);
                // enum all the types defined in the interop assembly
                System.Reflection.Assembly objAssembly =
                System.Reflection.Assembly.GetAssembly(typeof(IWorkspace));
                Type[] objTypes = objAssembly.GetTypes();
                // find the first implemented interop type
                foreach (Type currType in objTypes)
                {
                    // get the iid of the current type
                    Guid iid = currType.GUID;
                    if (!currType.IsInterface || iid == Guid.Empty)
                    {
                        // com interop type must be an interface with valid iid
                        continue;
                    }
                    // query supportability of current interface on object
                    IntPtr ipointer = IntPtr.Zero;
                    Marshal.QueryInterface(iunkwn, ref iid, out ipointer);
                    if (ipointer != IntPtr.Zero)
                    {
                        string str =currType.FullName;
                    }
                }

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts