VC写的dll,VB.net调用已经成功,C#调用失败,求解决办法
------------------------------------------
VC中dll的函数定义
# define DLLIMPORT __declspec (dllexport)
extern "C" int DLLIMPORT EnCode(char* sUnCoded,char* sEnCoded)
--------------------------------------
VB.net调用
Private Declare Ansi Function EnCode Lib "EnCode.dll" (ByVal o1 As String, ByVal o2 As String) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim un As String
Dim en As String
Dim rel As Integer
un = TextBox2.Text
en = "123456789012345678901234567890123456789012345678901234567890"
rel = EnCode(un, en)
If rel = 0 Then
TextBox1.Text = en.ToString
End If
End Sub
------------------------------------------------------
C#中试图调用方法
[DllImport("EnCode.dll",CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
private static extern int EnCode(string un,ref string en);
private void button1_Click(object sender, System.EventArgs e)
{
string aa = new string('0',50);
string bb = new string('1',6);
EnCode( bb,ref aa);
this.textBox2.Text = aa;
}
----------------------------------------------
其中private static extern int EnCode(string un,ref string en);
试图用private static extern int EnCode(string un,out string en);亦不成功
报错误
System.NullReferenceException: 未将对象引用设置到对象的实例。
at callencodedll.Form1.EnCode(String un, String& en)
...................................
请问对于VB.net可以用byVal传递的string类型,c#中应当用什么数据类型传递?