1. Managed type System Drawing.Color is automatically marshaled to VB type OLE_COLOR only in case of early binding. (see DealWithColor() method).
2. For class Component public variable DateTime dt can be used in both early and late binding cases, whereas public variable Color clr causes failure in late binding and works fine in early binding.
3. Method public void Info(MyPointClass pt) works fine with VB6 for both early and late binding but fails in VBScript.
Expand|Select|Wrap|Line Numbers
- [ComVisible(true)]
- public struct MYPOINT
- {
- // These are now private!
- private int xPos;
- private int yPos;
- [MarshalAs(UnmanagedType.BStr)]
- private string name;
- // Add some members to the MYPOINT struct.
- public void SetPoint(int x, int y) { xPos = x; yPos = y; }
- public void DisplayPoint() { MessageBox.Show(string.Format("X: {0} Y: {1}", xPos, yPos), name); }
- }
- [ComVisible(true)]
- [ClassInterface(ClassInterfaceType.AutoDual)]
- public class MyPointClass
- {
- private int xPos;
- private int yPos;
- private string name;
- public void SetPoint(string name, int x, int y) { this.name = name; xPos = x; yPos = y; }
- public void DisplayPoint() { MessageBox.Show(string.Format("X: {0} Y: {1}", xPos, yPos), name); }
- }
- [ComVisible(true)]
- [ClassInterface(ClassInterfaceType.AutoDual)]
- public class Component
- {
- // Success in Early Binding. Failure in Late Binding (Both VB6 and VBScript)
- public Color clr;
- // Success in Early Binding and Late Binding (Both VB6 and VBScript)
- public DateTime dt;
- // Success in Early Binding. Failure in Late Binding (Both VB6 and VBScript)
- public Color DealWithColor(Color col)
- {
- MessageBox.Show(col.ToString(), "DealWithColor() Method");
- return col;
- }
- // Success in Early Binding. TODO Late
- public void Info(ref MYPOINT pt)
- {
- pt.DisplayPoint();
- }
- // Success in Early Binding and Late Binding (Both VB6 and VBScript)
- public void Info (object pt)
- {
- (pt as MyPointClass).DisplayPoint();
- }
- // Success in Early Binding and in Late Binding VB6. Failure in VBScript.
- public void Info (MyPointClass pt)
- {
- pt.DisplayPoint();
- }
- }
Expand|Select|Wrap|Line Numbers
- 'Late Binding via VB6
- '''''''''''''''''''''''''''''''''''
- Dim ptc As CallNetFromVB6.MyPointClass
- Dim col1 As OLE_COLOR
- Dim objLate As Object
- Set objLate = CreateObject("CallNetFromVB6.Component")
- objLate.dt = Now 'Success
- Set ptc = New CallNetFromVB6.MyPointClass
- ptc.SetPoint "From Class", 11, 22
- objLate.Info_2 ptc 'Success
- objLate.clr = vbRed 'Fail
- col1 = objLate.DealWithColor(col) 'Fail
- 'Late Binding via VBScript
- ''''''''''''''''''''''''''''''''''
- Set objLate = CreateObject("CallNetFromVB6.Component")
- Set ptLate = CreateObject("CallNetFromVB6.MyPointClass")
- objLate.dt = Now 'Success
- Set ptc = New CallNetFromVB6.MyPointClass
- ptc.SetPoint "From Class", 11, 22
- objLate.Info_2 ptc 'Fail
- objLate.clr = vbRed 'Fail
- col1 = objLate.DealWithColor(col) 'Fail
Igor Ladnik
Barak Cohen