3

我有一个 DLL 函数,可以将文件转换为另一种格式。该函数产生多个文件作为输出。因此,它用输出文件的路径填充第二个参数。

C++ 函数定义如下:

int Convert(LPTSTR lpSource, TCHAR outputFileName[][MAX_PATH]);

如何混搭第二个参数,以便我的 C# 应用程序可以正确接收输出文件路径?

[DllImport("Convert.dll")]
private static extern int Convert(
  [MarshalAs(UnmanagedType.LPTStr)] string lpszSource,
  ????
);

提前致谢。

4

2 回答 2

0

I would make things simpler using C++/CLI (which is very good at building bridging layers between native C/C++ code and managed code).

Basically, you could write a thin C++/CLI layer that exposes a method that calls the native function in its body, and then copies the returned native strings into a gcnew-ly created array<String^>, and returns it to the C# managed caller.

于 2013-06-17T11:00:49.370 回答
0

我终于弄明白了。我将 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
);

谢谢大家的帮助。

于 2013-06-18T05:49:59.993 回答