2

Background: We have a COM object written in C#. We are working with another company that has code written in VB6. We need to send them VB6 code that creates and calls objects/methods from our COM object.

I created a .tlb file from the C# COM DLL file using RegAsm.exe provided by Microsoft. I then added this .tlb file as a reference in VB6 (Project->References->Browse...). It is also checked under Available References. It is not registered as COM+.

I used this article (C#/VB6 COM Example) as a reference for all this.

Problem: The issues is that I'm referencing this COM object in my VB6 project, but none of the objects/methods/namespaces show up. There must be something simple I'm missing, but what is it? Do I need to register this as COM+, or is the problem something else?

EDIT: More info about the project
OK, so I now have access to the source code, but apparently I was mistaken. It is in C++, not C#. Our test app for the C++ COM object was in C#, but the COM object itself is C++.

Now, my new question is how do I interface with this C++ DLL. My college mentioned that it "isn't a real COM object" so is there a way to interface with it other than adding it as a reference? If not then how do I make it into a COM object?

I need to access and use functions as well as objects from this DLL.

6
  • did you put ComVisible attributes on a class within your C# project? On any methods of the class? Commented Sep 28, 2010 at 17:38
  • 1
    Another way to check that: open the .tlb with the Object Explorer tool and see what's in it Commented Sep 28, 2010 at 18:19
  • I second Rup suggestion. See any classes show under the Object Explorer tool. If not then follow Kate's comment and make sure every is visible to COM. Commented Sep 29, 2010 at 18:15
  • Looked into the .tlb file. Nothing is there, but I don't have access to the C# code. All I have is the C# COM object DLL. I'll have to send some emails and get the code or have the developers add the attributes in. I'll update as things progress. Thanks for your help. Commented Sep 29, 2010 at 18:34
  • Added more info about the problem. Commented Sep 30, 2010 at 16:09

1 Answer 1

2

It sounds like you don't have a proper interface for your C# class... In C# to create a proper typelib you need to create an interface for your object. Otherwise the object appears in VB6 just as you described:

I.e.

[Guid("0C3A05D1-ADF0-4d82-84BC-B59A1AEF6235")]
public interface ISomeClass
{
    [DispId(1)]
    string Foo { get; }

    [DispId(2)]
    string Bar { get; }

    [DispId(3)]
    bool Baz { get; }

}

[Guid("59EA6033-9BF3-4123-B163-9AD1F958E179"),
 ProgId("SomeModule.SomeClass"),
 ClassInterface(ClassInterfaceType.None)]
public class SomeClass : ISomeClass
{

     public string Foo 
     {
         get 
         {
             return _foo;
         }
     }
 // More implimentation
 ...

See this code project article for more details.

Sign up to request clarification or add additional context in comments.

3 Comments

added new info about the problem.
Is it C++ or is it C style dll? C++ interop that isn't a proper Com DLL is going to be a serious pain in the but. Can't really help you out with what you have given, as there are many ways to interop with C++ dll's, you are going to have to supply more details and probably some of the C# test code...
I wound up having to re-write the DLL in c# and this worked great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.