Need to connect to C ++ DLL

I need to call C ++ API from C #. I was able to call the API, but the char [] parameters seem to be sorting incorrectly. Here's the C ++ signature:

Create2ptModel(double modelPowers[2], 
               double modelDacs[2], 
               int pclRange[2],
               double targetPowers[32], 
               double *dacAdjustFactor,
               unsigned short powerRampFactors[32], 
               BOOL bPCLDacAdjusted[32],
               char calibrationModel[32],
               char errMsg[1024])

      

and this is how I am trying to call it from C #

[DllImport("AlgorithmsLib.dll", EntryPoint = "_Create2ptModel@36", 
 ExactSpelling = true, CallingConvention = CallingConvention.StdCall, 
 CharSet = CharSet.Auto)]
private static extern AlgorithmStatus Create2ptModel(
    double[] modelPowers, 
    double[] modelDacs, 
    int[] pclRange, 
    double[] targetPowers, 
    ref double dacAdjustFactor, 
    ushort[] powerRampFactors, 
    bool[] bPCLDacAdjusted, 
    /**/char[] calibrationModel, 
    char[] errMsg/**/);

      

Any idea on how I can set it up correctly? Thanks in advance!

+2


a source to share


1 answer


  • Don't use CharSet.Auto

    , you know the lib character set, use that. If you let the machine guess, it might be wrong.

  • Are these parameters char[]

    empty? Are they inputs or outputs? If they are null terminated inputs, just use string

    instead char[]

    .



+3


a source







All Articles