locked
Questions on Usage of a .NET Component from VB6 and VBScript RRS feed

  • Question

  •  Hi All,

    We are dealing with .NET server component and COM clients written with VB6 and VBScript. And there are some problems we faced (please see code below).

     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.

              [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();

          }

    }

     

     

     

        '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

     

     Thanks.

    Igor Ladnik

    Barak Cohen

     

     

    Thursday, October 16, 2008 12:52 PM

Answers

  • Good afternoon Igor! This forum is for helping customers interoperating with Windows via our open protocol documentation. Your issue does not appear to be related to our protocol documentation. Your question may be better answered by posting on the '.NET Base Class Library' forum at http://social.msdn.microsoft.com/forums/en-US/netfxbcl/threads/.

    Regards,
    Bill Wesse

    Escalation Engineer
    Thursday, October 16, 2008 6:18 PM