473,394 Members | 1,841 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.

Populating an array<System::UInt32>^ from an unmanaged array in the new C++/CLI syntax


In the old MEC++ syntax I can do this:

// compile in VS 2005 shell with cl -clr:oldsyntax -LD ArrayCopyOldSyntax.cpp
#using <mscorlib.dll>

public __gc class CopyTest
{
private: System::UInt32 m_indeces __gc[];

public: CopyTest(unsigned int indeces __nogc[], unsigned int arrayLength)
{
m_indeces = __gc new System::UInt32[arrayLength];
System::Runtime::InteropServices::Marshal::Copy(Sy stem::IntPtr(indeces),
m_indeces, 0, arrayLength);
}
};
And there is a little magic there in that there is no Marshal::Copy overload
that takes an UInt32 __gc[] as an argument for the destination of the copy,
but the compiler happily accepts it and it simply invokes the Copy overload
that takes an Int32 __gc[] as the destination. In other words, it more or
less does an implied reinterpret_cast for you.

But the equivalent class in the new syntax will not compile:

// compile in VS 2005 shell with cl -clr -LD ArrayCopyNewSyntax.cpp
public ref class CopyTest
{
private: array<System::UInt32>^ m_indeces;

public: CopyTest(unsigned int indeces[], unsigned int arrayLength)
{
m_indeces = gcnew array<System::UInt32>(arrayLength);
System::Runtime::InteropServices::Marshal::Copy(Sy stem::IntPtr(indeces),
m_indeces, 0, arrayLength);
}
};

ArrayCopyNewSyntax.cpp(11) : error C2665: 'System::Runtime::InteropServices::Marshal::Copy'
: none of the 16 overloads could convert all the argument types

It appears that I can reinterpret_cast m_indeces to array<Int32>^ explicitly
and it will work, and of course I could always write my own loop to do the
copy, but is there a more elegant way to do this in the new syntax? The
Marshal.Copy overloads are very handy for interop code, but getting into
the habit of doing reinterpret casts on object handles doesn't seem like
a good idea.

-Bern McCarty
Dec 19 '06 #1
2 4287
Hi Dave,

Currently we will perform some research on this issue, I will update you as
soon as possible.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 20 '06 #2
Hi Bern,

I have already consulted this issue with our product team, there is no more
elegant way to achieve this in the new C++/CLI compiler. The VC2005
complier is more strict than VC2003's, I am afraid some MEC++'s approaches
may not work under VC2005.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 21 '06 #3

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

Similar topics

21
by: Patrick Dunford | last post by:
PHP allows control arrays in forms e.g. this is a counter editing script echo "<input name=\"counterdelname\" type=\"hidden\" value=\""; echo "<input name=\"countername\" type=\"hidden\"...
6
by: Deano | last post by:
I needed to have a listbox populated by locations which are stored in tblLocations. However I wanted an "All locations" entry to be at the top of the listbox. This is not in the tblLocations. The...
4
by: Sangeetha | last post by:
I came across this array initialisation which I can't follow ---------------------------------------------- public static string AllOperators { get {
0
by: Adam Clauss | last post by:
I have a class member declared as: System::String* fields __gc; I call an unmanaged method which returns a char** which I need to copy into the above array. Right now, I am looping through the...
2
by: Daniel Mori | last post by:
Hi, Im hoping someone can give me some advice. Im doing some development using VS Whidbey 2005 beta 1. Im about to implement some highly time critical code related to a managed collection of...
1
by: _DS | last post by:
My managed code needs to shuttle an unmanaged buffer between a couple unmanaged functions. I know this could be done via pin_ptr, and I understand the implications re managed heap fragmentation...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
2
by: berrylthird | last post by:
This question was inspired by scripting languages such as JavaScript. In JavaScript, I can access members of a class using array syntax as in the following example: var myInstance:myClass = new...
1
by: Charming12 | last post by:
Hi All, The question is regarding Unmanaged and Managed code conversion in C# for structures. I have two structures like: public struct Detail { public int age; public string address;
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...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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.