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.
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.
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
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?
Re: looking for interop example
type this into Google :
class library c#
or
class library vb.net
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?
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.
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.......