none
Using method written in C# within VB6 RRS feed

  • Question

  • Hi,

    I have created a class with one method returning a string value in C#.
    I have set COM-visibility, and using VS I have registered the assembly for COM interoperation.

    Then in a VB6 EXE application project I have added the previously registered COM component as a reference.

    Now I tried to access the C# method within a VB6 event handler method also by method name and class name, but VB6 IntelliSense did not show a sign of the C# method.

    Why is this?

    ( I have set COM-visibility for my class, for the method and also in the AssemblyInfo.cs file, and I have also added a strong name to the DLL. )

    Thx.

    Monday, July 13, 2009 4:56 PM

Answers

  • I found the solution which is kind of ridiculous :).

    The name of the type library is only shown by IntelliSense if I push the space button after writing:

    Dim myCOMRef As Object
    Set myCOMRef = ...

    It was not obvious for me.
    Tuesday, July 14, 2009 7:14 PM

All replies

  • What [InterfaceType] attribute did you use?  VB6 likes dual.

    Hans Passant.
    Monday, July 13, 2009 7:16 PM
    Moderator
  • At present I am trying to use this piece of code, and I can't access the method from VB6:

    using System.Runtime.InteropServices;
    
    namespace SampleCOMVisibleDLL
    {
       [InterfaceType(ComInterfaceType.InterfaceIsDual)]
       public interface IMyClass
       {
          string SayHello();
       }
    
       [ComVisible(true)]
       public class MyClass : IMyClass
       {
          [ComVisible(true)]
          public string SayHello()
          {
             return "hello from .NET";
          }
       }
    }

     

    Tuesday, July 14, 2009 5:56 AM
  • Do you have any idea for the solution?

    I also have another experience:
    I created a COM DLL in C++.
    After adding this C++ COM DLL to the VB6 project as a reference, I couldn't find any sign of it via VB6 IntelliSense.
    Tuesday, July 14, 2009 12:11 PM
  • Did you register it properly?

    Hans Passant.
    Tuesday, July 14, 2009 1:02 PM
    Moderator
  • I registered it via Visual Studio, that is, I checked the 'Register for COM interop' checkbox in project properties window.

    Also, when creating the reference in VB6, I don't reference it by filename, but I reference it by type library name.

    These are why I think that the registration was proper.
    Tuesday, July 14, 2009 1:06 PM
  • The name of my assembly is also enumerated in OLE/COM Object Viewer under Type Libraries section (after building the VS solution).
    I don't know if there is another/better way to monitor registered COM DLLs than OLE/COM Object Viewer.

    Tuesday, July 14, 2009 1:13 PM
  • I found the solution which is kind of ridiculous :).

    The name of the type library is only shown by IntelliSense if I push the space button after writing:

    Dim myCOMRef As Object
    Set myCOMRef = ...

    It was not obvious for me.
    Tuesday, July 14, 2009 7:14 PM
  • The Interop Forms Toolkit is nearly fool proof.
    Tuesday, July 14, 2009 7:18 PM