2

I want to use array in C# using CLI function.

CLI Source

public value struct Test
{
    int         nIndex;
    TArrTest    Arr;    // TArrTest : Array struct
}

void Api::Set_Test(array<Test^>^% _Test2)

C# Source

Test[] Test3 = new Test[5];
test3[0].nIndex = 0;
...
...
Api.Set_Test(ref Test3) // Error message

Error Message: The parameter is not convert ref Test[] to ref system.Value[].

How can I call Set_Test in C#?

1
  • 1
    Knowing when to use the ^ hat is super-duper important in C++/CLI. Only use it for reference types (ref class or ref struct). The % is not correct either, the C++/CLI function doesn't create the array. Delete both. Commented May 2, 2019 at 13:03

1 Answer 1

1

Your C++/CLI declaration:

void Api::Set_Test(array<Test^>^% _Test2)

is incorrect. The array is not an array of Test references, since Test is a value type. It should be

void Api::Set_Test(array<Test>^% _Test2)
                             ^------ remove the reference caret inside the angle brackets
Sign up to request clarification or add additional context in comments.

Comments

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.