array <Byte>^ to unsigned char*

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zon7mail@gmail.com

    #1

    array <Byte>^ to unsigned char*

    I've two functions. One is managed and receives an array, and the other
    is unmanaged and receives a pointer, just like this
    class A
    {
    int Foo(unsigned char* m){};
    ...
    }

    ref class B
    {
    int Boo(array< Byte >^ n){};
    ...
    }

    Is there anyway to call the function Foo from Boo passing n directly?

  • Carl Daniel [VC++ MVP]

    #2
    Re: array &lt;Byte&gt; ^ to unsigned char*

    zon7mail@gmail. com wrote:
    I've two functions. One is managed and receives an array, and the
    other is unmanaged and receives a pointer, just like this
    class A
    {
    int Foo(unsigned char* m){};
    ...
    }
    >
    ref class B
    {
    int Boo(array< Byte >^ n){};
    ...
    }
    >
    Is there anyway to call the function Foo from Boo passing n directly?
    Yes. Get a pin_ptr<Bytetha t references the first byte of n and pass it to
    Foo

    using namespace System;

    struct A
    {
    int Foo(unsigned char* m)
    {
    return *m;
    }
    };

    ref class B
    {
    A* m_pA;
    int Boo(array< Byte >^ n)
    {
    pin_ptr<unsigne d charpn = &n[0];
    return m_pA->Foo(pn);
    }
    };

    -cd


    Comment

    • Barry Kelly

      #3
      Re: array &lt;Byte&gt; ^ to unsigned char*

      zon7mail@gmail. com wrote:
      I've two functions. One is managed and receives an array, and the other
      is unmanaged and receives a pointer, just like this
      class A
      {
      int Foo(unsigned char* m){};
      ...
      }
      >
      ref class B
      {
      int Boo(array< Byte >^ n){};
      ...
      }
      >
      Is there anyway to call the function Foo from Boo passing n directly?


      -- Barry

      --

      Comment

      • Paul E Collins

        #4
        Re: array &lt;Byte&gt; ^ to unsigned char*

        zon7mail@gmail. com wrote:
        int Boo(array< Byte >^ n){};
        Can someone tell me what this ^ means? I'm still using the C# 1.x
        compiler (occasionally 2.x) and I only know ^ as the exclusive-or
        operator.

        Eq.


        Comment

        • Carl Daniel [VC++ MVP]

          #5
          Re: array &lt;Byte&gt; ^ to unsigned char*

          Paul E Collins wrote:
          zon7mail@gmail. com wrote:
          >
          >int Boo(array< Byte >^ n){};
          >
          Can someone tell me what this ^ means? I'm still using the C# 1.x
          compiler (occasionally 2.x) and I only know ^ as the exclusive-or
          operator.
          This questsion was misposted - it's about C++/CLI, where the ^ operator is
          used to derefence a "tracking pointer". It's roughly analogous to the '.'
          in C# between an object reference and a member name.

          -cd


          Comment

          Working...