H
hds6400
Unregistered / Unconfirmed
GUEST, unregistred user!
现有一个用Delphi写的dll为AutoWBPY.DLL,函数如下:
getbm( var str : shortstring ;
sel : integer);
在C#中采用以下两种方式调用都提示错误"未将对象引用设置到对象的实例":
方法一:
[DllImport("AutoWBPY.dll",EntryPoint="getbm",CharSet=CharSet.Auto,CallingConvention=CallingConvention.ThisCall)]
public unsafe static extern void getbm(ref string str,int sel);
private void button1_Click(object sender, System.EventArgs e)
{
string str=textBox2.Text;
unsafe
{
getbm(ref str,3);
}
}
方法二:
[DllImport("AutoWBPY.dll",EntryPoint="getbm",CharSet=CharSet.Auto,CallingConvention=CallingConvention.ThisCall)]
public unsafe static extern void getbm(char* str,int sel);
private void button1_Click(object sender, System.EventArgs e)
{
string str=textBox2.Text;
unsafe
{
fixed(char* temp=str)
{
getbm(temp,3);
}
}
}
getbm( var str : shortstring ;
sel : integer);
在C#中采用以下两种方式调用都提示错误"未将对象引用设置到对象的实例":
方法一:
[DllImport("AutoWBPY.dll",EntryPoint="getbm",CharSet=CharSet.Auto,CallingConvention=CallingConvention.ThisCall)]
public unsafe static extern void getbm(ref string str,int sel);
private void button1_Click(object sender, System.EventArgs e)
{
string str=textBox2.Text;
unsafe
{
getbm(ref str,3);
}
}
方法二:
[DllImport("AutoWBPY.dll",EntryPoint="getbm",CharSet=CharSet.Auto,CallingConvention=CallingConvention.ThisCall)]
public unsafe static extern void getbm(char* str,int sel);
private void button1_Click(object sender, System.EventArgs e)
{
string str=textBox2.Text;
unsafe
{
fixed(char* temp=str)
{
getbm(temp,3);
}
}
}