Calling C++ DLL function from C# where function arguments are pointers

The function declaration of the DLL in VC++ is:

B

OOL DLL_Search_Peaks (WORD wProcessCode, WORD wDataCount, double* pdblWavelength, double* pdblSpectrumPower, double dblThresholdUniform, double* pdblThresholdProfile, WORD* pwPeakCount, double* pdblPeakWavelength, double* pdblPeakPower, double* pdblPeakFWHM);

C

an someone help me with C# equivalent for the datatypes like double*, WORD*, etc?

I have tried like through the following way:

[DllImport(" Sense2020E.dll ", EntryPoint = "DLL_Search_Peaks")]
public static extern bool DLL_Search_Peaks(ushort wProcessCode, ushort wDataCount, ref double[] pdblWavelength, ref double pdblSpectrumPower,double dblThresholdUniform, ref double [] pdblThresholdProfile, ref uint[] pwPeakCount,ref double[] pdblPeakWavelength,ref double[] pdblPeakPower, ref double[] pdblPeakFWHM );

There are no errors in compiling and running. After running, if I set a breakpoint, I get only zeros on the parameters.

Can someone please help me with this?

The search peaks function call is as follows in vc++:

void CMyDllTesterDlg::OnButtonGetSpectrum()
{
    WORD    i, wPeakCount;    
    double  dblTemp, pdblPwr[PIXEL_COUNT], pdblWL[PIXEL_COUNT], pdblPeakWL[PIXEL_COUNT], pdblPeakPwr[PIXEL_COUNT], pdblPeakFWHM[PIXEL_COUNT];    
    CString strData;
    
    UpdateData(TRUE);
    
    m_ctrlListData.ResetContent();
    
    if (!m_bDeviceOK)    
    {    
        m_ctrlListData.AddString("Device Not Opened!");    
        return;    
    }
    
    UpdateProcessCode();
    
    wPeakCount = 0;
    
    memset(pdblWL, 0, 8 * PIXEL_COUNT);    
    memset(pdblPwr, 0, 8 * PIXEL_COUNT);    
    memset(pdblPeakWL, 0, 8 * PIXEL_COUNT);    
    memset(pdblPeakPwr, 0, 8 * PIXEL_COUNT);    
    memset(pdblPeakFWHM, 0, 8 * PIXEL_COUNT);
    
    m_ctrlListData.ResetContent();
    
    if (!DLL_Acquire_Snapshot_Spectrum(pdblWL, pdblPwr, &dblTemp))
    {    
        m_ctrlListData.AddString("Get Snapshot Spectrum Data Failed!");
        return;   
    }
    
    strData.Format("FBGA Temperature: %.3f", dblTemp);
    
    m_ctrlListData.AddString(strData);
    
    if (m_bSubtractBGD)    
    {   
        for (i = 0; i < m_wPixelCount; i++)    
            pdblPwr[i] -= m_pdblBackground[i];
    }
    
    if (m_bThresholdUniform)    
    {  
        if (!DLL_Search_Peaks(m_wProcessCode, m_wPixelCount, pdblWL, pdblPwr, m_dblThresholdUniform, NULL,
            &wPeakCount, pdblPeakWL, pdblPeakPwr, pdblPeakFWHM))
        {
            m_ctrlListData.AddString("Search peak Failed!");
            return;
        }
    
        if (wPeakCount != 0)
        {
            strData.Format("Peak Count: %d", wPeakCount);
    
            m_ctrlListData.AddString(strData);
    
            if (m_bLoadCalib)
                strData = "Peak Wavelength (nm), Peak Intensity (Count), Peak FWHM (nm)";
            else
                strData = "Peak Pixel, Intensity (Count), Peak FWHM (pixel)";
    
            m_ctrlListData.AddString(strData);
    
            for (i = 0; i < m_wPixelCount; i++)
            {
                strData.Format("%.3f,    %.1f,  %.4f", pdblPeakWL[i], pdblPeakPwr[i], pdblPeakFWHM[i]);
                m_ctrlListData.AddString(strData);
            }

Does your C++ test program for the C++ DLL work correctly?

I think you need to drop the ‘ref’:

[DllImport(" Sense2020E.dll ", EntryPoint = "DLL_Search_Peaks")]
public static extern bool DLL_Search_Peaks(ushort wProcessCode, ushort wDataCount, double[] pdblWavelength, 
ref double pdblSpectrumPower,double dblThresholdUniform, double [] pdblThresholdProfile, 
uint[] pwPeakCount, double[] pdblPeakWavelength, double[] pdblPeakPower, double[] pdblPeakFWHM );

but that might be for if they are input parameters and not output parameters.

Show us your C# calling code.