5 Replies Latest reply on Jul 31, 2012 1:21 PM by sshetty

    Getting the real COM class name

    haffner
      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???
        • Re: Getting the real COM class name
          kenbuja
          Have you tried something like this (in VB.NET)

          If TypeOf IFeature Is IComplexEdgeFeature Then
            
          End If
          
          • Re: Getting the real COM class name
            Neil
            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.

            Dim layer As IFeatureLayer = New FeatureLayer
                            Dim s As String = layer.GetType.FullName
            • Re: Getting the real COM class name
              haffner
              Ken, you are absolutely right, it is possible to check it this way:
              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.
              • Re: Getting the real COM class name
                haffner
                Neil, perhaps I'm doing somthing wrong here, cause I've tried this:
                IWorkspace pWorkspace = EsriDatabase.FileGdbWorkspaceFromPath("WhatEver.gdb");
                Console.WriteLine(pWorkspace.GetType().FullName);

                This code outputs "System.__ComObject" no matter which interface or class I use.
                • Re: Getting the real COM class name
                  sshetty
                  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

                   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;
                                  }
                              }