المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Calling a C function from C# and getting values from it.



C# Programming
06-30-2009, 04:50 PM
I have a C function of format:
func1(double param[], int size);

This function is called from C# code the following syntax:
[DllImport("first.dll", EntryPoint = "func1", CallingConvention = CallingConvention.StdCall)]
public static extern int func1(ref double param[], int size);

The function 'func1' takes two parameters: the array in which values should be filled up from C dll and 'size' which tells the number of values to fill in the array.
Now if the param[] array is declared as param[] = new double[5]; and the 'size' parameter is given as 10, still the function passes.
Wherase the same scenario in direct C application, gives error saying "Array size(i.e. 5) is lesser than the number of values to fill(i.e. 10)".

I am not able to reproduce the same behavior in .Net. Can anybody help me with it?