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!
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.Are those
char[]
parameters null terminated? Are they inputs or outputs? If they are null-terminated inputs, then just usestring
instead ofchar[]
.
精彩评论