From: Edwin on
Just for the record, here's what I do:

Header of the called function:

public static int Function2(ref byte pBufData, uint nSize);


So if I want to call this function and pass a byte array to it, I do this:

private void Function1()
{
try
{
byte[] pBufData = new byte[50];
uint nSize = 0;

// Fill up the pBufData with relevant data
pBufData[0] = 0x34;
...
// Calculate the size of the byte array
...
// Call the function
public static int Function2(ref pBufData[0], nSize);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}

HTH
Cheers



Pramod wrote:

Cannot convert 'ref byte[]' to 'ref byte'
18-Sep-08

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

Previous Posts In This Thread:

On Monday, September 15, 2008 11:12 AM
kareem11 wrote:

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(a)gmail.com> schrieb im Newsbeitrag
news:e8712e86-9924-4c26-a4cd-e98a54a7ff1f(a)x16g2000prn.googlegroups.com...

On Thursday, September 18, 2008 6:47 AM
Pramod wrote:

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

On Thursday, September 18, 2008 6:47 AM
Jon Skeet [C# MVP] wrote:

Re: Cannot convert 'ref byte[]' to 'ref byte'
I do not think you want to be passing it by ref. Just pass the byte[]
(which is a reference already) by value.

Jon

On Thursday, September 18, 2008 6:48 AM
Pramod wrote:

Re: Cannot convert 'ref byte[]' to 'ref byte'
Thanks for your reply. I have tried passing it by value it still says
that 'Cannot convert 'ref byte[]' to 'byte'

On Thursday, September 18, 2008 6:48 AM
Jon Skeet [C# MVP] wrote:

Re: Cannot convert 'ref byte[]' to 'ref byte'
On Sep 16, 4:39=A0pm, Pramod <ipra...(a)gmail.com> wrote:


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


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Binding Beyond the Limitation of Name Scopes
http://www.eggheadcafe.com/tutorials/aspnet/ef583104-e507-491d-b05f-49faac8854c8/wpf-binding-beyond-the-li.aspx
From: Arne Vajhøj on
On 11-06-2010 08:50, Edwin Decoene wrote:
> Just for the record, here's what I do:

> Cannot convert 'ref byte[]' to 'ref byte'
> 18-Sep-08

My guess is that the poster has found a solution during those 1.5 year!

Arne