通过引用将字符**从c#传递到非托管c++;
这是C代码通过引用将字符**从c#传递到非托管c++;,c#,c++,pinvoke,C#,C++,Pinvoke,这是C代码 该方法写入传入的字符串数组。有没有办法从c#调用此方法,并让非托管代码能够写入字符串数组?这很有效,感谢Remus Rusanu的链接提供了答案。我要做的就是在lst参数上用[In,Out]来装饰 namespace CameraTest { class Program { static void Main(string[] args) { int maxCam = 10, ma
该方法写入传入的字符串数组。有没有办法从c#调用此方法,并让非托管代码能够写入字符串数组?这很有效,感谢Remus Rusanu的链接提供了答案。我要做的就是在lst参数上用[In,Out]来装饰
namespace CameraTest
{
class Program
{
static void Main(string[] args)
{
int maxCam = 10,
maxChar = 33;
var lst = (new object[maxCam]).Select(o => new string(' ', maxChar)).ToArray();
bool sync = true;
bool ret = CameraCalls.CAM_EnumCameraEx(sync, lst, maxCam, maxChar);
}
}
public static class CameraCalls
{
[DllImport("CamDriver64.dll")]
public static extern bool CAM_EnumCameraEx(bool sync,
[In, Out]
string[] lst,
long maxCam,
long maxChar);
}
}
该文档有一个答案,我所要做的就是在中使用,然后用
StringBuilder[]
测试我的答案,并得到堆栈不平衡错误,所以我认为@HansPassant是正确的。仍然很高兴我创建了一个新的数组,数组中的任何对象都已经在扩展:)在我添加[In,Out]之前,它要么不设置字符串,要么抛出内存异常。那么,如果[In,Out]是错误的,那么从外部方法获取数据的正确方法是什么?我应该用什么来代替long?我不愿意花时间帮忙。你已经回答了自己的问题,这表明你已经下定决心了。
BOOL WINAPI CAM_EnumCameraEx(BOOL bSynchronized, char **ppCameraList, long lMaxCamera, long lMaxCharacter);
namespace CameraTest
{
class Program
{
static void Main(string[] args)
{
int maxCam = 10,
maxChar = 33;
var lst = (new object[maxCam]).Select(o => new string(' ', maxChar)).ToArray();
bool sync = true;
bool ret = CameraCalls.CAM_EnumCameraEx(sync, lst, maxCam, maxChar);
}
}
public static class CameraCalls
{
[DllImport("CamDriver64.dll")]
public static extern bool CAM_EnumCameraEx(bool sync,
[In, Out]
string[] lst,
long maxCam,
long maxChar);
}
}