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:
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."
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
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
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'
Re: Cannot convert 'ref byte[]' to 'ref 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
Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Binding Beyond the Limitation of Name Scopes
http://www.eggheadcafe.com/tutorial...f-49faac8854c8/wpf-binding-beyond-the-li.aspx