C#结构到C++;编组问题
我调用C++中的C++函数。< /p>C#结构到C++;编组问题,c#,.net,pinvoke,marshalling,dllimport,C#,.net,Pinvoke,Marshalling,Dllimport,我调用C++中的C++函数。< /p> 这是C++中的函数标头: int src_simple (SRC_DATA *data, int converter_type, int channels) ; 这是等价的C函数: [DllImport("libsamplerate-0.dll")] public static extern int src_simple(ref SRC_DATA sd, int converter_type, int channels); 这是C++中的SRC
这是C++中的函数标头:
int src_simple (SRC_DATA *data, int converter_type, int channels) ;
这是等价的C函数:
[DllImport("libsamplerate-0.dll")]
public static extern int src_simple(ref SRC_DATA sd, int converter_type, int channels);
这是C++中的SRCI数据结构,然后是C</P> 这是我定义的C#结构:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SRC_DATA
{
public IntPtr data_in, data_out;
public long input_frames, output_frames;
public long input_frames_used, output_frames_gen;
public int end_of_input;
public double src_ratio;
}
最大的问题是,最后一个参数SRCGRUN不能正确地传递给C++函数,(它把它看作是0或是无效的)。p> 我的声明正确吗
<谢谢> < p>你强制装箱C,而不是C++。可能发生的是C++编译器用四个附加字节填充7个32字节,以确保双字节是8字节对齐的。检查<代码> > PrimaPACK/<代码>编译器指令。
< P>强制打包C,而不是C++。可能发生的是C++编译器用四个附加字节填充7个32字节,以确保双字节是8字节对齐的。检查<代码> > PrimaPARCUT/<代码>编译器指令。< /P> < P>检查C++编译器中int的大小。C的int总是32位。
检查C++编译器中int的大小。C#int始终是32位。您确定问题出在src#u比率成员中吗?C#中的long是64位。在C++上,Win32平台长为32位,我认为你需要在C++中使用int来构造长C++结构成员。另外,PACK=1看起来有点奇怪,在C++中使用相同的结构成员对齐吗?< P>你确定问题在SRCI比率成员中吗?C#中的long是64位。在C++上,Win32平台长为32位,我认为你需要在C++中使用int来构造长C++结构成员。另外,PACK=1看起来有点奇怪,在C++中使用相同的结构成员对齐吗?< /P>你是对的,PACK=1是错误的。我只是让它使用默认值:)你是对的,pack=1是个错误。。我只是让它使用默认值:)[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SRC_DATA
{
public IntPtr data_in, data_out;
public long input_frames, output_frames;
public long input_frames_used, output_frames_gen;
public int end_of_input;
public double src_ratio;
}