2

I have a .net C# function that takes an double array as the first parameter and passes back another double precision array based on the first.

C# Code

public int testMath(double[] InputSet, double[] OutputSet)
{
    // more complicated than what I am showing but
   for (int i = 0; i < 3; i++)
   {
      OutputSet[i] = InputSet[i] * 2.0;
   }
   return 1;  // Really something else
}

PHP

$mathTest = new DOTNET("MathTest,"
        ."Version=1.0.0.0,"
        ."Culture=neutral,"
        ."PublicKeyToken=213536b1e6bb8ea5"
        , "MathTest.MathTest");

$inputValue = Array();
$outputValue = Array();

for ($i = 0; $i < 3; $i++){
  $inputValue[$i] = $i * 3.0;
  $outputValue[$i] = 0.0;
}

$status = $mathTest->testMath($inputValue, $outputValue);

When I try to run this I get an error that parameter 1 is a type mismatch.
I have other routines that take doubles as inputs and by ref outputs that work as I would expect. I can call this routine from other programming languages but I am stumped as to how to get it to work in PHP. I tried viewing the parameters using com_print_typeinfo and found that both arguments show up as VT_SAFEARRAY as IN. I did some testing to change argument 1 to be an OUT and it made it worse (won't run at all). Any suggestions would be greatly appreciated.

1
  • Seriously, why does it need to happen in C#? Or the other way round? This seems like a terrible thing to do. Commented May 24, 2013 at 14:00

1 Answer 1

1

the most simple approch imo would be to encode the double array as json.

from php

json_encode ($myarr);

or

  json_decode ($myarr); // if u want the other direction

and then just catch it in the c# (or vice versa) and decode it. u can use json.net or jsonFx etc.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that worked. I had not use json before so I had to install it on my Visual Studio configuration. After a few misteps I got it to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.