Use .net dll in VB6?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Use .net dll in VB6?

  1. #1
    Join Date
    Nov 2004
    Posts
    24

    Use .net dll in VB6?

    I want use a .net dll in vb6. I have selected "Register for COM Interop" in VS.net proyect. I have registered dll with resgam. I have generated .tlb file. I have add in references tlb file. But when I run it tak error "File or asembly name xxxx , or one of its components, was not found".

    Before register with resgam the error was "ActiveX component can't create object".
    Do you know how use .net dlls in vb6?
    Thanks
    _______________
    Hip Hop
    Foro heavy

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Use .net dll in VB6?

    Take a look at this tutorial http://msdn.microsoft.com/library/de...ertutorial.asp. This might help a bit in understanding how COM interop actually works. This is in C# but should be helpful in this case.

  3. #3
    Join Date
    Nov 2004
    Posts
    24

    Re: Use .net dll in VB6?

    Thanks I have solve it.
    But now I have another problem, when I write "object." it don't shome the public methods of the class (after write dot).
    If I write method it runs ok, but can I show the methods of the class when I write dot after de object?
    Thanksss

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Use .net dll in VB6?

    Quote Originally Posted by wakeup
    Thanks I have solve it.
    But now I have another problem, when I write "object." it don't shome the public methods of the class (after write dot).
    If I write method it runs ok, but can I show the methods of the class when I write dot after de object?
    Thanksss
    This is because you are use Late Binding. Late Binding means that compiler will only come to know about the actual ActiveX at run-time. This is the reason why inteli-sense of VB doesn't work when you declare objects using generic object class.

  5. #5
    Join Date
    Nov 2004
    Posts
    24

    Re: Use .net dll in VB6?

    How can I solve it?
    thanks

  6. #6
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Use .net dll in VB6?

    Quote Originally Posted by wakeup
    How can I solve it?
    thanks
    You will have to use Early-Binding. I would declare my object like this to
    Code:
    Dim myObject As New NetObjectClass
    Where NetObjectClass is the names of the Class you created in .NET.

  7. #7
    Join Date
    Nov 2004
    Posts
    24

    Re: Use .net dll in VB6?

    I have tried it but inteli-sense don't work.


    PD: Sorry, my english is bad, i'm spanish.

  8. #8
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Use .net dll in VB6?

    Quote Originally Posted by wakeup
    I have tried it but inteli-sense don't work.
    This means that the Class you developed in VB.NET does not have a public interface. You should define a public interface for your class. This way VB 6.0 intelli-sense will be able to show all the public methods/properties of your VB.NET class
    Quote Originally Posted by wakeup
    PD: Sorry, my english is bad, i'm spanish.
    I am also not from an English speaking country. So no worries

  9. #9
    Join Date
    Nov 2004
    Posts
    24

    Re: Use .net dll in VB6?

    This is the code of the test-dll. The class and the test method are public.

    Code:
    	public class ClasePrueba
    	{
    		public ClasePrueba()
    		{
    		}
    
    		public  int prueba(int a, int b)
    		{
    			return a * b +5;
    		}
    	}
    This is you have told me?
    thankss

  10. #10
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Use .net dll in VB6?

    I don't see an INterface defined for the Class. I have modified your test class and included an Interface that contains the definition of the public members of the class. Take a look at the code, copy it and Compile the assembly again (don't forget to check "Register for COM Interop in the project properties)
    Code:
    //define a public interface which will contain all the public members of the class
    //the methods that are not public should nto be written in the interface
    public interface iClasePrueba{
    public int prueba(int a, int b);
    public string Hello(string sMessage);
    }
    //implement the interface defined above 
    public class ClasePrueba : iClasePrueba
    {
    //constructor
    public ClasePrueba()
    {
    }
    publicint prueba(int a, int b)
    {
    return a * b +5;
    }
    //Another property just to show how interface works
    publicstring Hello(string sMessage)
    {
    return "Hello " + sMessage + " from witrhin .NET";
    } 
    }

    If you have written your class in C#, then you should have posted this thread inn C#.


  11. #11
    Join Date
    Nov 2004
    Posts
    24

    Re: Use .net dll in VB6?

    I have tried it, and intellinense don't appear.
    Then I have searched in google and I have seen this.
    http://www.vb-helper.com/howto_vb6_use_net_dll.html

    I have write
    Code:
    [ClassInterface(ClassInterfaceType.AutoDual)]
    Before class definition and intelliense is ok.

    Do you know what is exactly this ?
    Code:
    [ClassInterface(ClassInterfaceType.AutoDual)]
    Thanks

  12. #12
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Use .net dll in VB6?

    Using ClassInterFace.AutoDual will publish the Type information for the Class, that needs to be exposed to COM clients, to a Type Library.
    ClassInterFace indicates the type of Class Interface that needs to be generated for class that is exposed to the COM.
    AutoDial should not be used because of versioning issues.

    Lookup in MSDN for more details on this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center