C#调用VB编写的dll

来源:百度知道 编辑:UC知道 时间:2024/06/30 17:52:35
在VB中编写的ActiveX DLL 中代码为:
Public Function CheckName(ByVal ShpName As String) As Boolean
Dim i As Integer
Dim Flag As Boolean

Flag = False
For i = 1 To ActiveDocument.Shapes.Count
If ActiveDocument.Shapes(i).Name = ShpName Then
Flag = True
Exit For
End If
Next

If Flag Then '该名称已被使用
CheckName = True
Else
CheckName = False
End If
End Function

已经成功生成DLL:CheckName.dll
怎么在C#.NET中调用此DLL
最好说的具体点并附加代码!!!
我生成的DLL为工程1.dll

例子:
using System;
using System.Runtime.InteropServices;

namespace Anytao.net
{
class MainClass
{
[DllImport("User32.dll")]
public static extern int MessageBox(int hParent, string msg, string caption, int type);

static int Main()
{
return MessageBox(0, "How to use attribute in .NET", "Anytao_net", 0);
}
}
}

你的错误有两个可能,
一是,vb生成的dll组件有问题,所以调用失败

二是,已经成功生成DLL:CheckName.dll
[DllImport("工程1.dll")]
调用的组件书写不正确,应该是[DllImport("CheckName.dll")]

你可以用ImportDll在程序声明一下你的DLL,然后再使用其中的函数。使用时可用当做内部函数使用了!

[ImportDll]

keyi

C#和VB的dll是通用的,直接在工程的引用里添加,然后在文件头using一下就可以了