0

i wanted to run a c++ function in c# via dll and pass few doubles. The easiest way i found to pass multiple values is to predefine pointers and safe the values there.

However, here comes the question do i have to free the memory in c# and if yes, how can i delete the pointers?

Thanks!

[DllImport(CppPokerOddsCalculatorDLL, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public static unsafe extern void CalculateOdds_2Hands_Test(string myHand1_param, string myHand2_param, double* res1, double* res2, double* res3);

    static void Main(string[] args)
    {
        unsafe
        {
            double res1 = 0;
            double res2 = 0;
            double res3 = 0;
            double* p_res1 = &res1;
            double* p_res2 = &res2;
            double* p_res3 = &res3;


            CalculateOdds_2Hands_Test("AhAc", "3h3c", p_res1, p_res2, p_res3);

            Console.WriteLine(res1);
            Console.WriteLine(res2);
            Console.WriteLine(res3);
        }           
    }

0 Answers0