发贴两天了!!谁能解决C#调用VB写的DLL
在VB中写的testDll.dll,并编译了,代码(已经通过VB调用的测试)如下:
Option Explicit
Public Function jia(ByVal a As Long, ByVal b As Long) As Long
Dim s As Long
s = a + b
jia = s
End Function
C#的form代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace test11
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
c1 c = new c1();
c.Jia(1,2);
}
}
}
c#中类c1的代码如下:
using System;
using System.Runtime.InteropServices;
namespace test11
{
/// <summary>
/// c1 的摘要说明。
/// </summary>
public class c1
{
public c1()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
[DllImport("testDll.dll")]
private static extern void jia(int a,int b);
public void Jia(int pX,int pY)
{
int i;
i=jia( pX, pY);
}
}
}
已经把testDll.dll拷到了bin\Debug的目录;还在 项目->添加引用 把它引用进来了
运行程序错误提示:"无法在 DLL testDll.dll 中找到名为 jia 的入口点"
注意:1 不是要调用API
2 private static extern void jia改为private static extern int jia也是一样的
或者看贴:http://community.csdn.net/Expert/topic/4149/4149505.xml?temp=.642544