Cannot convert 'ref byte[]' to 'ref byte'

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

    #1

    Cannot convert 'ref byte[]' to 'ref byte'

    Hi.

    I have a C++ method which accepts - byte* - and I am calling this
    method from a C# application. I have created a byte[] to pass by ref.
    This is how I call the C++ method:

    Method(ref byteArray);

    However, this results in following error:
    Cannot convert 'ref byte[]' to 'ref byte'

    Here is my C++ method declaration:
    Method(byte* byteData);


    Please let me know how do I pass the byte[] to this method.

    Thanks in advance,
    PSI
  • Jon Skeet [C# MVP]

    #2
    Re: Cannot convert 'ref byte[]' to 'ref byte'

    On Sep 15, 3:50 pm, Pramod <ipra...@gmail. comwrote:
    I have a C++ method which accepts - byte* - and I am calling this
    method from a C# application. I have created a byte[] to pass by ref.
    I don't think you want to be passing it by ref. Just pass the byte[]
    (which is a reference already) by value.

    Jon

    Comment

    • =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?=

      #3
      Re: Cannot convert 'ref byte[]' to 'ref byte'

      Hi,

      there are a couple of things that can
      go wrong here:

      1.) Is it a IN or OUT parameter, e.g. does
      the function write to the pointer or does it
      expect something to go in to the function?

      2) which implies that the byte[] size is unknown.

      So the questions are the following. Do you
      expect something from the function written
      back to the pointer or does the function expect
      a ready filled array to operate on it?

      Depending on your answer we will find a
      appropriate solution for you,...

      Regards

      Kerem


      --
      -----------------------
      Beste Grüsse / Best regards / Votre bien devoue
      Kerem Gümrükcü
      Latest Project: http://www.codeplex.com/restarts
      Latest Open-Source Projects: http://entwicklung.junetz.de
      -----------------------
      "This reply is provided as is, without warranty express or implied."
      "Pramod" <ipramod@gmail. comschrieb im Newsbeitrag
      news:e8712e86-9924-4c26-a4cd-e98a54a7ff1f@x1 6g2000prn.googl egroups.com...
      Hi.
      >
      I have a C++ method which accepts - byte* - and I am calling this
      method from a C# application. I have created a byte[] to pass by ref.
      This is how I call the C++ method:
      >
      Method(ref byteArray);
      >
      However, this results in following error:
      Cannot convert 'ref byte[]' to 'ref byte'
      >
      Here is my C++ method declaration:
      Method(byte* byteData);
      >
      >
      Please let me know how do I pass the byte[] to this method.
      >
      Thanks in advance,
      PSI

      Comment

      • Pramod

        #4
        Re: Cannot convert 'ref byte[]' to 'ref byte'

        On Sep 15, 8:12 pm, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
        On Sep 15, 3:50 pm, Pramod <ipra...@gmail. comwrote:
        >
        I have a C++ method which accepts - byte* - and I am calling this
        method from a C# application. I have created a byte[] to pass by ref.
        >
        I don't think you want to be passing it by ref. Just pass the byte[]
        (which is a reference already) by value.
        >
        Jon
        Thanks for your reply. I have tried passing it by value it still says
        that 'Cannot convert 'ref byte[]' to 'byte'


        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: Cannot convert 'ref byte[]' to 'ref byte'

          On Sep 16, 4:39 pm, Pramod <ipra...@gmail. comwrote:
          Thanks for your reply. I have tried passing it by value it still says
          that 'Cannot convert 'ref byte[]' to 'byte'
          If you haven't got the "ref" keyword in the method call, that sounds
          very unlikely. The method you're calling should (by the sounds of it)
          probably be declared to take byte[] rather than byte though. Did you
          by any chance change the C++ instead of the calling code?

          Jon

          Comment

          Working...