渔翁大哥啊救命啊,关于C#调用vb写的DLL中函数的问题。。100分裸体跪等。。。
小弟现在要用vb(只会vb)写一个加密函数,根据大侠们的方法编译成不用注册的标准dll(这个dll在vb中成功调出mdk5函数)给公司的另外一个同事用(他用C#)
vb代码如下
Private Declare Function GetPhyCode Lib "kspdll.dll " (ByVal prodcode As String, ByVal hostcode As String, ByVal IsNumber As Long, ByVal decode As String) As Long
。。。。。(这个代码中包含引用一个dll和若干给mdk5的函数)。。。
由于太长不让贴身略了。。。
Public Function mdk5(ByVal sn As String) As Long '加密
Dim tempstr2 As String
Dim ssid
hostid = getdiskname( "a ")
ssid = "colakesp "
tempstr2 = Space(12) '分配空间
Call GetPhyCode(ssid, hostid, 1, tempstr2)
ssid2 = Mid(tempstr2, 5, 8)
Dim tempstr3 As String
tempstr3 = Space(12) '分配空间
Call GetPhyCode(ssid2, "e0009999 ", 1, tempstr3)
codetemp = "A01 " & "- " & "e0009999 " & tempstr3
If sn = codetemp Then
mdk5 = 1
Else
mdk5 = 0
End If
End Function
Sub Main()
'确保VB能编译
End Sub
Function DLLMain(ByVal hInstDLL As Long, ByVal fdwReason As Long, ByVal lpwReserved As Long) As Long
DLLMain = 1
End Function
现在要在c#中调用mdk5函数
同事c#中
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;//这是用到DllImport时候要引入的包
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
mdk5( "111111111111 ");
}