Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Interface and GetType() - works in C# but not in VB?

Interface and GetType() - works in C# but not in VB?

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpquestioncsharpcom
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David Hovey
    wrote on last edited by
    #1

    Hi again. I have another question hopefully someone can help me with. I've found articles online where it is said that an Interface does not have a GetType() function as it is not derived from 'Object'. This seems true since when trying to work with the IDataObject interface, there is no GetType() function. The problem is, as my last post addresses, I'm trying to change code from C# to VB for drag and dropping from Outlook. The original C# code is shown below. The very Odd thing I don't understand is how in C# GetType() works with IDataObject. Inside the DragDrop event of an Windows Form object e.Data.GetType() is usable, but this is not the case in VB. I have the below code converted to VB but the New constructor does not work since there is no GetType() functions "visible." Thanks again!!

        private System.Windows.Forms.IDataObject underlyingDataObject;
        private System.Runtime.InteropServices.ComTypes.IDataObject comUnderlyingDataObject;
        private System.Windows.Forms.IDataObject oleUnderlyingDataObject;
        private MethodInfo getDataFromHGLOBLALMethod;
    
        public OutlookDataObject(System.Windows.Forms.IDataObject underlyingDataObject)
        {
            //get the underlying dataobject and its ComType IDataObject interface to it
            this.underlyingDataObject = underlyingDataObject;
            this.comUnderlyingDataObject = (System.Runtime.InteropServices.ComTypes.IDataObject)this.underlyingDataObject;
          
            //get the internal ole dataobject and its GetDataFromHGLOBLAL so it can be called later
            FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
            this.oleUnderlyingDataObject = (System.Windows.Forms.IDataObject)innerDataField.GetValue(this.underlyingDataObject);
            this.getDataFromHGLOBLALMethod = this.oleUnderlyingDataObject.GetType().GetMethod("GetDataFromHGLOBLAL", BindingFlags.NonPublic | BindingFlags.Instance);
        }
    
    C B 2 Replies Last reply
    0
    • D David Hovey

      Hi again. I have another question hopefully someone can help me with. I've found articles online where it is said that an Interface does not have a GetType() function as it is not derived from 'Object'. This seems true since when trying to work with the IDataObject interface, there is no GetType() function. The problem is, as my last post addresses, I'm trying to change code from C# to VB for drag and dropping from Outlook. The original C# code is shown below. The very Odd thing I don't understand is how in C# GetType() works with IDataObject. Inside the DragDrop event of an Windows Form object e.Data.GetType() is usable, but this is not the case in VB. I have the below code converted to VB but the New constructor does not work since there is no GetType() functions "visible." Thanks again!!

          private System.Windows.Forms.IDataObject underlyingDataObject;
          private System.Runtime.InteropServices.ComTypes.IDataObject comUnderlyingDataObject;
          private System.Windows.Forms.IDataObject oleUnderlyingDataObject;
          private MethodInfo getDataFromHGLOBLALMethod;
      
          public OutlookDataObject(System.Windows.Forms.IDataObject underlyingDataObject)
          {
              //get the underlying dataobject and its ComType IDataObject interface to it
              this.underlyingDataObject = underlyingDataObject;
              this.comUnderlyingDataObject = (System.Runtime.InteropServices.ComTypes.IDataObject)this.underlyingDataObject;
            
              //get the internal ole dataobject and its GetDataFromHGLOBLAL so it can be called later
              FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
              this.oleUnderlyingDataObject = (System.Windows.Forms.IDataObject)innerDataField.GetValue(this.underlyingDataObject);
              this.getDataFromHGLOBLALMethod = this.oleUnderlyingDataObject.GetType().GetMethod("GetDataFromHGLOBLAL", BindingFlags.NonPublic | BindingFlags.Instance);
          }
      
      C Offline
      C Offline
      cterrinw
      wrote on last edited by
      #2

      Hi David, I am having the same problem, I can get the oleUnderlyingDataObject ok but I am unable to get the method getDataFromHGLOBLAL. The last line of code returns nothing... Did you find a resolution to this? Regards Bill Terrington

      Public Sub New(ByVal underlyingDataObject As System.Windows.Forms.IDataObject)
      'get the underlying dataobject and its ComType IDataObject interface to it
      Me.underlyingDataObject = underlyingDataObject
      Me.comUnderlyingDataObject = DirectCast(Me.underlyingDataObject, System.Runtime.InteropServices.ComTypes.IDataObject)

           'get the internal ole dataobject and its GetDataFromHGLOBLAL so it can be called later 
           Dim innerDataField As FieldInfo = CType(Me.underlyingDataObject, Object).\[GetType\].GetField("innerData", BindingFlags.NonPublic Or BindingFlags.Instance)
      
           Me.oleUnderlyingDataObject = DirectCast(innerDataField.GetValue(Me.underlyingDataObject), System.Windows.Forms.IDataObject)
           Me.getDataFromHGLOBLALMethod = CType(Me.oleUnderlyingDataObject, Object).\[GetType\].GetMethod("getDataFromHGLOBLAL", BindingFlags.NonPublic Or BindingFlags.Instance)
      

      End Sub

      D 1 Reply Last reply
      0
      • C cterrinw

        Hi David, I am having the same problem, I can get the oleUnderlyingDataObject ok but I am unable to get the method getDataFromHGLOBLAL. The last line of code returns nothing... Did you find a resolution to this? Regards Bill Terrington

        Public Sub New(ByVal underlyingDataObject As System.Windows.Forms.IDataObject)
        'get the underlying dataobject and its ComType IDataObject interface to it
        Me.underlyingDataObject = underlyingDataObject
        Me.comUnderlyingDataObject = DirectCast(Me.underlyingDataObject, System.Runtime.InteropServices.ComTypes.IDataObject)

             'get the internal ole dataobject and its GetDataFromHGLOBLAL so it can be called later 
             Dim innerDataField As FieldInfo = CType(Me.underlyingDataObject, Object).\[GetType\].GetField("innerData", BindingFlags.NonPublic Or BindingFlags.Instance)
        
             Me.oleUnderlyingDataObject = DirectCast(innerDataField.GetValue(Me.underlyingDataObject), System.Windows.Forms.IDataObject)
             Me.getDataFromHGLOBLALMethod = CType(Me.oleUnderlyingDataObject, Object).\[GetType\].GetMethod("getDataFromHGLOBLAL", BindingFlags.NonPublic Or BindingFlags.Instance)
        

        End Sub

        D Offline
        D Offline
        David Hovey
        wrote on last edited by
        #3

        Sorry but I never did find the solution. Not sure if you are using the same code I was (Providing for drag and drop from Outlook)? I ended up using the original C# code and creating a C# library that my VB program referenced. Then I ended up using an online code converter and now the program is in c# anyway... Sorry couldn't be more helpful.

        C 1 Reply Last reply
        0
        • D David Hovey

          Sorry but I never did find the solution. Not sure if you are using the same code I was (Providing for drag and drop from Outlook)? I ended up using the original C# code and creating a C# library that my VB program referenced. Then I ended up using an online code converter and now the program is in c# anyway... Sorry couldn't be more helpful.

          C Offline
          C Offline
          cterrinw
          wrote on last edited by
          #4

          I have already created a c library but was hoping to avoid the overhead if possible. Thanks for the reply anyway.

          1 Reply Last reply
          0
          • D David Hovey

            Hi again. I have another question hopefully someone can help me with. I've found articles online where it is said that an Interface does not have a GetType() function as it is not derived from 'Object'. This seems true since when trying to work with the IDataObject interface, there is no GetType() function. The problem is, as my last post addresses, I'm trying to change code from C# to VB for drag and dropping from Outlook. The original C# code is shown below. The very Odd thing I don't understand is how in C# GetType() works with IDataObject. Inside the DragDrop event of an Windows Form object e.Data.GetType() is usable, but this is not the case in VB. I have the below code converted to VB but the New constructor does not work since there is no GetType() functions "visible." Thanks again!!

                private System.Windows.Forms.IDataObject underlyingDataObject;
                private System.Runtime.InteropServices.ComTypes.IDataObject comUnderlyingDataObject;
                private System.Windows.Forms.IDataObject oleUnderlyingDataObject;
                private MethodInfo getDataFromHGLOBLALMethod;
            
                public OutlookDataObject(System.Windows.Forms.IDataObject underlyingDataObject)
                {
                    //get the underlying dataobject and its ComType IDataObject interface to it
                    this.underlyingDataObject = underlyingDataObject;
                    this.comUnderlyingDataObject = (System.Runtime.InteropServices.ComTypes.IDataObject)this.underlyingDataObject;
                  
                    //get the internal ole dataobject and its GetDataFromHGLOBLAL so it can be called later
                    FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
                    this.oleUnderlyingDataObject = (System.Windows.Forms.IDataObject)innerDataField.GetValue(this.underlyingDataObject);
                    this.getDataFromHGLOBLALMethod = this.oleUnderlyingDataObject.GetType().GetMethod("GetDataFromHGLOBLAL", BindingFlags.NonPublic | BindingFlags.Instance);
                }
            
            B Offline
            B Offline
            BrianHoover
            wrote on last edited by
            #5

            David Hovey wrote:

            The problem is, as my last post addresses, I'm trying to change code from C# to VB for drag and dropping from Outlook. The original C# code is shown below. The very Odd thing I don't understand is how in C# GetType() works with IDataObject. Inside the DragDrop event of an Windows Form object e.Data.GetType() is usable, but this is not the case in VB.

            Translate C#: FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance); TO VB: Dim innerDataField As FieldInfo = CObj(Me.underlyingDataObject).GetType().GetField("innerData", BindingFlags.NonPublic Or BindingFlags.Instance) Fred

            D 1 Reply Last reply
            0
            • B BrianHoover

              David Hovey wrote:

              The problem is, as my last post addresses, I'm trying to change code from C# to VB for drag and dropping from Outlook. The original C# code is shown below. The very Odd thing I don't understand is how in C# GetType() works with IDataObject. Inside the DragDrop event of an Windows Form object e.Data.GetType() is usable, but this is not the case in VB.

              Translate C#: FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance); TO VB: Dim innerDataField As FieldInfo = CObj(Me.underlyingDataObject).GetType().GetField("innerData", BindingFlags.NonPublic Or BindingFlags.Instance) Fred

              D Offline
              D Offline
              David Hovey
              wrote on last edited by
              #6

              Thanks Fred. Although it certainly has been awhile since I posted that. Where were you then!? hahaha. Just a joke. When I couldn't figure it out I ended up using a .NET library to keep the C# code as it was. Then as it turned out, because I needed more C# experience, I ported my program over to C# and didn't need the code in VB anyway. All kidding aside. Great work.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups