Results 1 to 7 of 7

Thread: looking for interop example

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2008
    Posts
    22

    looking for interop example

    Is there a good example on using C# with vb.net 2008 or above. I am looking for the simplest example. A class library I would be able to write with C# and use from vb.net. Probably a .dll I would imagine.

    Could someone recommend some search strings for this forum I can try? I am looking for the shortest simplest example.

    None of my searches list anything.
    Last edited by frozenbrain; Apr 15th, 2010 at 08:12 AM.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Dec 2008
    Posts
    22

    Re: looking for interop example

    Here is one of my basic questions.

    After writing a class library in Visual C# 2008 Express on one computer. What file from that project do I have to copy over to another computer running Visual basic 2010 Express. How do I add it to the VB project and what would be an example use of a function from the library. for example MyFunc(). As I said, very beginner stuff, but I want to make sure I follow decent programming guidelines for project management and etc. So I am looking for some advice on this.

  3. #3
    Frenzied Member
    Join Date
    Jul 2009
    Posts
    1,103

    Re: looking for interop example

    If i am not getting you wrong then you want to create a dll in c# and use that dll in a vb project right?

    Quote Originally Posted by frozenbrain View Post
    A class library I would be able to write with C# and use from vb.net. Probably a .dll I would imagine.
    If you are able to write a class library in C# then why dont you try it out by taking some work of your own?

    If you find my reply helpful , then rate it

  4. #4
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: looking for interop example

    type this into Google :

    class library c#

    or

    class library vb.net
    VB.NET MVP 2008 - Present

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2008
    Posts
    22

    Re: looking for interop example

    For some reason, searching doesn't work. I googled it though and solved the problem, but it leads to another question.

    1. copy the dll over to a directory of choice.
    2. Add a reference to the .dll in your vb project.
    3. Add an Imports statement for example

    Imports ClassLibrary1

    4. Add an object reference

    Dim Test As New Class1

    5. Use the function.

    Test.MyFunc()



    The question that comes up is about adding an object reference. Am I doing something wrong? Is this not supposed to be transparent to using the function?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: looking for interop example

    Why do you think you're doing something wrong? If something is happening that you don't expect, or something is not happening that you do expect, then you should explain what that is.

    It IS transparent. Every time you create a VB project you're using libraries created with C# because almost the entire .NET Framework was written in C#. When you create a form, the System.Windows.Forms.dll library containing the Form class was written in C#. Etc, etc.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Frenzied Member
    Join Date
    Jul 2009
    Posts
    1,103

    Re: looking for interop example

    consider an example where you have this code in your class library:

    Code:
    Namespace Base1     
                
                Public Class Class1
             
                End Class
    
                Namespace Sub1
    
                         Public Class Class2
                
                         End Class
     
                End Namespace
      
             End Namespace
      
             Namespace Base2
      
                   Public Class Class3
       
                   End Class
      
             End Namespace
    And suppose after building the project you'll have a DLL called myDll, then

    Code:
    myDll.Base1.Class1
    myDll.Base1.Sub1.Class2
    myDll.Base2.Class3

    The underlined part is the namespace,the root namespace being the myDll and every other namespace and class is a 'child' of that namespace either directly (Base1 and Base2) or indirectly (Sub1, Class1, Class2 and Class3).

    and about the object reference,you need to create an object of the class before using the class.......

    If you find my reply helpful , then rate it

Posting Permissions

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



Click Here to Expand Forum to Full Width