473,396 Members | 2,004 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,396 software developers and data experts.

Coping one array to another in Managed C++

How can I copy 5 bytes from the middle of one array to another in Managed C++?
The following code segment causes the compilation errors below:

unsigned char cResult __gc[] = new unsigned char __gc[256];
unsigned char cBuf __gc[] = new unsigned char __gc[256];
....
strncpy(cBuf, (cResult + 10), 5);

***********************************************

error C2690: '+' : cannot perform pointer arithmetic on a __gc array
error C2664: 'strncpy' : cannot convert parameter 1 from 'unsigned char
__gc[]' to 'char *'
Can only convert a __gc array to or from Object * or Array *

***********************************************

Can anyone clarify this situation, please.

Nov 17 '05 #1
3 4147
for(int i=0;i<5;i++)
cBuf[i] = cResult[10+i];

"Steve" <St***@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
How can I copy 5 bytes from the middle of one array to another in Managed C++? The following code segment causes the compilation errors below:

unsigned char cResult __gc[] = new unsigned char __gc[256];
unsigned char cBuf __gc[] = new unsigned char __gc[256];
...
strncpy(cBuf, (cResult + 10), 5);

***********************************************

error C2690: '+' : cannot perform pointer arithmetic on a __gc array
error C2664: 'strncpy' : cannot convert parameter 1 from 'unsigned char
__gc[]' to 'char *'
Can only convert a __gc array to or from Object * or Array *

***********************************************

Can anyone clarify this situation, please.

Nov 17 '05 #2
You could do something like this:

strncpy((unsigned char*)&cBuf[0], ((unsigned char*)&cResult[0])+10, 5);

This should also work IMO.

Martin

Steve wrote:
How can I copy 5 bytes from the middle of one array to another in Managed C++?
The following code segment causes the compilation errors below:

unsigned char cResult __gc[] = new unsigned char __gc[256];
unsigned char cBuf __gc[] = new unsigned char __gc[256];
...
strncpy(cBuf, (cResult + 10), 5);

***********************************************

error C2690: '+' : cannot perform pointer arithmetic on a __gc array
error C2664: 'strncpy' : cannot convert parameter 1 from 'unsigned char
__gc[]' to 'char *'
Can only convert a __gc array to or from Object * or Array *

***********************************************

Can anyone clarify this situation, please.

Nov 17 '05 #3
Array.Copy?
http://msdn.microsoft.com/library/de...copytopic3.asp

"Steve" <St***@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
How can I copy 5 bytes from the middle of one array to another in Managed
C++?
The following code segment causes the compilation errors below:

unsigned char cResult __gc[] = new unsigned char __gc[256];
unsigned char cBuf __gc[] = new unsigned char __gc[256];
...
strncpy(cBuf, (cResult + 10), 5);

***********************************************

error C2690: '+' : cannot perform pointer arithmetic on a __gc array
error C2664: 'strncpy' : cannot convert parameter 1 from 'unsigned char
__gc[]' to 'char *'
Can only convert a __gc array to or from Object * or Array *

***********************************************

Can anyone clarify this situation, please.

Nov 17 '05 #4

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

Similar topics

16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
5
by: Cybertof | last post by:
Hello, Is it possible to convert a VB6 Array of Struct to a C# Array Of Struct ? The test context is a C# application calling a VB6 ActiveX DLL Function using UDT (User Defined Type) and...
4
by: ned | last post by:
I have been having a lot of problems with an array of structures embedded in another structure in C++ .NET and have boiled it down to this very simple example: Try the following steps, it will...
2
by: symbol | last post by:
I am having this problem in a managed c++ DLL which mixes managed and unmanaged C/C++ code. I tried to assign value to a struct array nested in another struct. but I can only write to the first...
1
by: symbol | last post by:
I am having this problem in a managed c++ DLL which mixes managed and unmanaged C/C++ code. I tried to assign value to a struct array nested in another struct. but I can only write to the first...
9
by: mupe | last post by:
Hi, i have a problem with a Type Library, which is written in C++. I am developing an application in C#.NET and have to use functions from this COM-Type Library. When I use these functions in...
17
by: mr.resistor | last post by:
hey i am having a few problems calling a C DLL from C#. i am using a simple function that takes an array of floats and an integer as an input, but i cannot seem to get it to work. when i try to...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
5
by: Dmitriy Lapko | last post by:
Hallo all Is it possible to change schema of table in DB2 v.8.2 without recreating and coping a table into a new schema? I need it for several purposes, one of them - refactoring of existing...
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:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.