Can't change the VB6 variant type in .net4.0 RRS feed

  • Question

  • the case is like this:

    1. COM module raise an event, the .net module change the byref parameter(Variant type) and passed it back to COM.

    2. usually the parameter should be changed, but it still unchanged.


    1 if the parameter type is string or integer but not variant, then the parameter will be changed by .net module successfully

    2. if run it in .net4.5 environment, it will succeed too.

    Can somebody give an explanation?

    ------------------------VB6 MyEvent module------------

    Option Explicit

    Public Event OnListExRequest(Parameter)

    Public Event OnListExRequestDonet(Parameter As String)

    Public Sub RaiseOnListExRequest(Parameter)
        RaiseEvent OnListExRequest(Parameter)
    End Sub

    Public Sub RaiseOnListExRequestDonet(Parameter)
        RaiseEvent OnListExRequestDonet(Parameter)
    End Sub

    -------------------------VB6 usercontrol module

    Private eve2 As MyEvent

    Public Sub SetEvent(evt As MyEvent)
        Set eve2 = evt
        MsgBox "Event object is nothing: " + CStr(eve2 Is Nothing)
        Dim str As Variant
        str = "first string"

        MsgBox "Original string value: " + str
        eve2.RaiseOnListExRequest str
        MsgBox "string value after event raised: " + str
    End Sub

    --------------------------.net winform module--------

            public Form1()

            private void button1_Click(object sender, EventArgs e)
                var evt = new NewPrj.MyEvent();
                evt.OnListExRequest += evt_OnListExRequest;
                var uc = new NewPrj.UserControl1();
                uc.SetEvent(ref evt);

            void evt_OnListExRequest(ref object Parameter)
                Parameter = "changed string";

    Wednesday, October 24, 2012 2:44 AM

All replies

  • It seems that the CLR cannot marshal the complex object by default.

    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Wednesday, October 24, 2012 11:54 AM