473,394 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
Sep 15 '08 #1
4 5299
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
Sep 15 '08 #2
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" <ip*****@gmail.comschrieb im Newsbeitrag
news:e8**********************************@x16g2000 prn.googlegroups.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
Sep 15 '08 #3
On Sep 15, 8:12*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
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'
Sep 16 '08 #4
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
Sep 16 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Prabhu | last post by:
Hi, I have to send a structure through TCPClient socket. we can send only byte array through the socket, So please any one can help me by telling How to convert a struct object into an byte...
2
by: Mel WEaver | last post by:
Hello, I have the following delphi structure for a binary file. I'm looking for idea how to read this file. Mel type TMenuDataStruct = packed record exename : string;
4
by: kishor | last post by:
I have an activeX dll, I am calling one function from that dll. I am using C# as coding language. I am getting following error. cannot convert from 'string' to 'ref string' How do I call this...
15
by: Wilfried Mestdagh | last post by:
Hello, probably a beginners question :) I have this code sample in VB: if (objResults.Item(1).etc Translate this into C# if (objResults.etc But compiler complains about the index '1'...
6
by: centrino | last post by:
hi, I import a funtion fromm dll file: dll function header : DWORD WINAPI Enumerate( HANDLE hWDMHandle, PNDIS_STATUS pNStatus,
8
by: Gee | last post by:
I get the above error with this code and I can't figure out why? Any ideas please? See code below - the actual error is included in the code: public struct NETRESOURCE { public Int32...
3
by: Chris | last post by:
Hi, I have the following procedure below: I am getting 2 errors on compile: Argument '2': cannot convert from 'System.Data.SqlClient.SqlDataReader' to 'ref...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
10
by: =?Utf-8?B?Um95?= | last post by:
What is the way to have best performance to copy a byte to a value such as long? I use BitConverter.ToInt64(binary, offset) But the performace is not good enough. I need to have the best...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.