VB.NET调用C#写的DLL
逆鳞92 2015-10-16 11:25:50 在网上查找了很多,没有一个很好的DEMO,而且各种说法,有的说.NET平台可以直接引用,不同的语言,语法格式都不一样这个说法很扯淡,还有的说要包成COM注册后才能调用,那要是换到其他的电脑怎么使用,微软这么多低层DLL文件调用,应该有比较通用的调用方法,本人小白,折腾了两天没能解决,麻烦大家给个思路!谢谢!
测试CODE
C# DLL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace DemoCom
{
public class ComTest
{
public String getSum(String str1, String str2)
{
return str1 + str2;
}
}
}
VB.NET 调用
Imports System
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.IO.Ports
'<Out()>
Public Class Form1
<DllImport("DemoCom.dll", EntryPoint:="getSum")>
Public Shared Function getSum(ByVal inputData As String, ByVal outputData As String) As Integer
End Function
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Try
Dim inputdata As String = "zzq"
Dim outputdata As String = "lhh"
Dim result As String = ""
result = getSum(inputdata, outputdata)
TextBox1.Text = (result)
Catch ex As Exception
TextBox2.Text = (ex.ToString())
End Try
End Sub
End Class
最后显示System.EntryPointNotFoundException: Unable to find an entry point named 'getSum' in DLL 'DemoCom.dll'.
at WindowsAppDLLTest.Form1.getSum(String inputData, String outputData)
at WindowsAppDLLTest.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\alion.zhou.CHROMA\Desktop\DLLTest\WindowsAppDLLTest\WindowsAppDLLTest
找不到DLL文件中的getSum函数,我在网上看到的这种调用,好像不能,麻烦大神指点!