المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Exposing functions from C# class to VB code



C# Programming
01-23-2010, 09:50 AM
Hello,
I have a code snippet in a class library:

[Guid("3E29D375-F4E3-4e87-95A2-16DBC655F896")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class TestUtilityClass
{

public TestUtilityClass()
{
}


//ComVisible attribut controls accessibility of an individual managed type or member,
//or of all types within an assembly, to COM
public string HelloWorld()
{
return "Hello World";
}
public int GetSomeInteger()
{
return 100;
}

public void GetStringVal(out string name)
{
name = "ABC";
}
}
[Guid("D7C64ED0-7D5F-4809-9A1A-B4F6595A9374")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class MyClass
{
public MyClass()
{
}

public string HellWorld()
{
return "Hello World From Myclass";
}
public int GetSomeInt()
{
return 50;
}

public void GetStrVal(out string name)
{
name = "ABC From MyClass";
}
}


I build the class library project, and then generate the type lib by doing regasm.
Then I add the reference in the VB project and expect the functions to be seen and called in VB code.
But when there is only one class say TestUtilityClass class in the namespace I can see the functions.
When I add another class MyClass I am unable to see the functions in the VB after I create an object of the class and try to use it.
To add to this, I don't see the functions of the class in the typelib when I open the typelib file.
Can someone let me know the reason for this behavior and the way to resolve it?