marshal c++ reference to int

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jonpb

    marshal c++ reference to int

    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("xfor m400.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.AccessVi olationExceptio n.

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

    Thanks
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: marshal c++ reference to int

    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.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "jonpb" <nospam@nospam. comwrote in message
    news:ePlZJWrPJH A.764@TK2MSFTNG P05.phx.gbl...
    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("xfor m400.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.AccessVi olationExceptio n.
    >
    I tried a few more possible solutions but I cannot find the correct one.
    >
    Thanks

    Comment

    • Ben Voigt [C++ MVP]

      #3
      Re: marshal c++ reference to int



      "jonpb" <nospam@nospam. comwrote in message
      news:ePlZJWrPJH A.764@TK2MSFTNG P05.phx.gbl...
      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("xfor m400.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.AccessVi olationExceptio n.
      >
      I tried a few more possible solutions but I cannot find the correct one.
      You should use "ref" on the angle parameter.
      >
      Thanks

      Comment

      Working...