Interface and GetType() - works in C# but not in VB?
-
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); }
-
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); }
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
-
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
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.
-
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.
-
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); }
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
-
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
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.