目前由于业务需要,用c#写了一个com组件,需要放在vb中调用,由于本人之前没有用过vb开发过项目,在现学现用的时候遇到些问题,有劳牛人们解答!
大致是这样,现在C#中定义一个公有方法,其中带有委托参数,这个方法(接口)需要在vb中调用,但按C#中的写法在VB中实现,运行就提示:参数不可选!
C#代码:
public Class TestClass:ITestClass
{
public void Login(string uName, string uPwd, SocketServiceStatusHandler handle)
{
if (handler != null)
{
OnSocketServiceStatusChanged = null;
OnSocketServiceStatusChanged += new SocketServiceStatusHandler_handler);
} }
}
public delegate void SocketServiceStatusHandler(SocketServiceStatusEventArg e); C#调用:
private void btnLogin_Click(object sender, EventArgs e)
{
TestClass testClass = new TestClass();
//登陆处理
testClass.Login("xxx", "xxxx", ShowConnectMessage);
}
private void ShowConnectMessage(SocketServiceStatusEventArg e)
{
if (this.InvokeRequired)
{}
} VB的调用COM方式:
Public m_testClass As New TestClass
Private Sub Command1_Click()
Set aa = testClass.Login("xxx", "xxxx", ShowConnectMessage) End Sub
Public Function ShowConnectMessage(ByVal e As SocketServiceStatusEventArg) End Function 还有一个问题,在VB中不能调用C#中的静态成员吗?急等
大致是这样,现在C#中定义一个公有方法,其中带有委托参数,这个方法(接口)需要在vb中调用,但按C#中的写法在VB中实现,运行就提示:参数不可选!
C#代码:
public Class TestClass:ITestClass
{
public void Login(string uName, string uPwd, SocketServiceStatusHandler handle)
{
if (handler != null)
{
OnSocketServiceStatusChanged = null;
OnSocketServiceStatusChanged += new SocketServiceStatusHandler_handler);
} }
}
public delegate void SocketServiceStatusHandler(SocketServiceStatusEventArg e); C#调用:
private void btnLogin_Click(object sender, EventArgs e)
{
TestClass testClass = new TestClass();
//登陆处理
testClass.Login("xxx", "xxxx", ShowConnectMessage);
}
private void ShowConnectMessage(SocketServiceStatusEventArg e)
{
if (this.InvokeRequired)
{}
} VB的调用COM方式:
Public m_testClass As New TestClass
Private Sub Command1_Click()
Set aa = testClass.Login("xxx", "xxxx", ShowConnectMessage) End Sub
Public Function ShowConnectMessage(ByVal e As SocketServiceStatusEventArg) End Function 还有一个问题,在VB中不能调用C#中的静态成员吗?急等
call testClass.Login("xxx", "xxxx", ShowConnectMessage)
就成了