2010-05-05 63 views
2

我需要从C#调用C++ API。我已经能够调用API,但char []参数似乎没有正确编组。 这里的C++签名:需要连接到C++ DLL

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]) 

,这是我正在试图把它从C#

[DllImport("AlgorithmsLib.dll", EntryPoint = "[email protected]", 
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/**/); 

,我可以马歇尔如何正确任何想法? 在此先感谢!

+0

这两个星号在C#中的calibrationModel的左边是一个错字吗? – 2010-05-05 16:02:47

+0

我觉得他试图强调他们。我已经格式化了代码。 – 2010-05-05 16:03:54

回答

3
  1. 不要使用CharSet.Auto你知道lib的字符集,使用它。如果你让机器猜测,它可能会猜错。

  2. 这些参数是否为char[]?他们是输入还是输出?如果它们是空端接输入,则只需使用string而不是char[]

+0

这是正确的。 CharSet.Ansi是必需的,char []必须是字符串。 – 2010-05-05 17:02:49