C#调用vc++的dll出现问题,请大家帮忙谢谢!
vc++中dll的函数声明是:#define DLL_PORT_TYPE __declspec(dllexport)
#define DLL_PORT_FUNCTION_TYPE __stdcall
DLL_PORT_TYPE BOOL DLL_PORT_FUNCTION_TYPE DLL_Search_Peaks(WORD wPeakSearchMode,WORD wPixelCount,double* pdblWL,double* pdblPwr,double dblNoiseThreshold,double* pdblNoiseThresholdProfile,DWORD* pdwPeakInfo);
在c#中我声明为:
[DllImport("Sense2020Dll.dll",CharSet = CharSet.Ansi)]
public static extern bool DLL_Search_Peaks(ushort wPeakSearchMode, ushort wPixelCount, ref double[] pdblWL, ref double pdblPwr,double dblNoiseThreshold, ref double[] pdblNoiseThresholdProfile, ref uint[] pdwPeakInfo);
调用:
double[] pdblNoiseThresholdProfile = new double[512];
uint[] pdwPeakInfo= new uint[512];
double[] pdblWL=new double[512];
double[] pdblPwr = new double[512];
if (DLL_Search_Peaks(0, 512, pdblWL,pdblPwr, 2000,pdblNoiseThresholdProfile,ref pdwPeakInfo) == true)
{
......
}
(1)如向c#声明double*为ref double[],DWORD*声明为ref uint[],编译没有错误,调试状态下在if处设断点,则会出现未处理的“System.ArgumentException”类型的异常,其他信息: 方法的类型签名与 Interop 不兼容。
(2)如声明double*为double[],DWORD*声明为uint[],编译及运行都不会出现错误,在运行完if后一句设断点,只得到pdwPeakInfo[0]的值,其他值均为0。
哪位高手知道是怎么回事,能不能帮忙解决一下谢谢了