如何编组二维TCHAR数组
How to marshal two dimensional TCHAR array?
我有一个将文件转换为另一种格式的DLL函数。该函数生成多个文件作为输出。因此,它用输出文件的路径填充第二个参数。
c++函数定义如下:
int Convert(LPTSTR lpSource, TCHAR outputFileName[][MAX_PATH]);
我如何mashal第二个参数,使我的c#应用程序可以正确接收输出文件路径?
[DllImport("Convert.dll")]
private static extern int Convert(
[MarshalAs(UnmanagedType.LPTStr)] string lpszSource,
????
);
我会使用 c++/CLI(它非常擅长在本地C/c++代码和托管代码之间构建桥接层)来使事情变得更简单。
基本上,您可以编写一个瘦c++/CLI层,它暴露了一个方法,该方法在其主体中调用本机函数,然后将返回的本机字符串复制到gcnew
-ly创建的 array<String^>
中,并将其返回给c#托管调用者。
我终于想通了。我把我的c++函数改成如下:
int Convert(LPTSTR lpSource, LPTSTR *plpOutputFileName, int size);
c#声明为:
[DllImport("Convert.dll")]
private static extern int Convert(
[MarshalAs(UnmanagedType.LPTStr)] string lpszSource,
[In, Out] String[] outputFileName,
int size
);
谢谢大家的帮助。
相关文章:
- 将二维矢量传递给类
- 将值从二维数组输出到文本文件
- 我在二维向量中是否正确分配了内存
- 带结构的二维矢量:如何存储元素
- 在二维数组中查找最小值和最大值?
- 移动二维数组中的字符
- C++ 传递二维字符数组
- 如何正确填充在堆上分配的二维数组?
- 传递二维数组时出现问题
- 具有随机数的二维数组不会更改
- 如何在C++中获取二维数组中最少的一列数?
- 如何使用用户输入变量制作二维数组?
- C++ 中的二维整数数组,每行中的元素数量不均匀
- C++ 中动态二维数组的访问冲突
- 在二维向量或数组中可以存储的最大元素数是多少?
- 如何将整数字符串转换为整数的二维向量?
- 二维矢量数据成员
- 遍历二维数组的所有子数组
- 将二维数组的所有元素插入到一维数组中
- 如何编组二维TCHAR数组