2010-05-05 77 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