C# string 转char*
我在C#中使用了C++生成的dll,由于dll的原型函数参数 是char*,所以导致C#中的 string变量传递有误(编译正确,输出结果有误),请问怎么办?代码如下:
//C++ dll源码:
...
EXPORT void _stdcall setFeature(char* _feature);
...
//C#调用 源码:
[DllImport("LicenseDll.dll", CharSet = CharSet.Ansi)]//C#调用C++ dll的指令
static extern int setFeature(string feature);
// static extern int setFeature(char* feature);
static void Main(string[] args)
{
......
string kk = "f2";
setFeature(kk);//编译正确,结果有误
setFeature("f2");//);//编译 结果都正确
......
}