marshal c++ reference to int

  • Thread starter Thread starter jonpb
  • Start date Start date
J

jonpb

Hi, I cannot find the correct attributes to marshal the following
unmanaged function signature:

void WINAPI GeomVec2AngleD(const Vector2RecD& v1, const Vector2RecD& v2,
double& angle)

I thought this would work:

[DllImport("xform400.dll")]
public static extern void GeomVec2AngleD([In] Point2D v1, [In] Point2D
v2, [In, Out] double angle);

Point2D's layout maps directly to Vector2RecD, there is no problem
there, the problem is, as soon as the C++ code attempts to write to
angle it throws a System.AccessViolationException.

I tried a few more possible solutions but I cannot find the correct one.

Thanks
 
jonpb,

You can not use references through the P/Invoke layer.

Rather, you will have to expose a function which takes pointers instead,
and marshal that function. Then, your function would just make the call to
the original function.
 
jonpb said:
Hi, I cannot find the correct attributes to marshal the following
unmanaged function signature:

void WINAPI GeomVec2AngleD(const Vector2RecD& v1, const Vector2RecD& v2,
double& angle)

I thought this would work:

[DllImport("xform400.dll")]
public static extern void GeomVec2AngleD([In] Point2D v1, [In] Point2D v2,
[In, Out] double angle);

Point2D's layout maps directly to Vector2RecD, there is no problem there,
the problem is, as soon as the C++ code attempts to write to angle it
throws a System.AccessViolationException.

I tried a few more possible solutions but I cannot find the correct one.

You should use "ref" on the angle parameter.
 
Back
Top