开发者

Need to interface to a C++ DLL

I need to call a C++ API from C#. I have been able to call the API, but the char[] parameters do not seem to be marshalling correctly. 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, 
    re开发者_如何学Gof double dacAdjustFactor, 
    ushort[] powerRampFactors, 
    bool[] bPCLDacAdjusted, 
    /**/char[] calibrationModel, 
    char[] errMsg/**/);

Any idea of how I can marshall it correctly? Thanks in advance!


  1. Don't use CharSet.Auto you know the character set of the lib, use that. If you let the machinery guess, it could guess wrongly.

  2. Are those char[] parameters null terminated? Are they inputs or outputs? If they are null-terminated inputs, then just use string instead of char[].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜