user441521
user441521

Reputation: 6998

Marshalling error when using a C++ library from a C# application

I am trying to use a C++ DLL in C# and having some issues between the two with a specific function.

In C++ the function is defined as:

byte* GetEntityUserData(TEntity entity)

In C# I've defined it as:

[DllImport(EngineDll)]
public static extern object[] GetEntityUserData(TEntity entity);

When I try to do the following usage:

object[] o = LE.GetEntityUserData(entity);

I get the following error:

Cannot marshal 'return value': Invalid managed/unmanaged type combination.

The C# program compiles, but it gives the run-time error.

Upvotes: 0

Views: 392

Answers (1)

Adam Robinson
Adam Robinson

Reputation: 185703

What is the data supposed to represent? I would change the C# signature to return byte[], not object[]. You won't be able to get a reference type back from an unmanaged function. Only value types, which means primitive types and struct's.

Upvotes: 3

Related Questions