473,799 Members | 3,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

struggling with __gc arrays as parameters

Hi All,

I am fairly new to Managed C++ extensions. I started trying to implement a
interface defined in a C# project, in C++. The problem was with passing
value arrays from c# to c++. I found examples on the web which worked, but
found mine didn't. After narrowing down the interface I found what I believe
to be the problem. The order of the parameters! The code below shows the
function that does not compile named QueryPositionsF orward. When reversing
the parameters illustrated by function QueryPositionsR everse, all appears to
work. ildasm reveals that the function, when reversed, compiles to the same
signature as the c# interface with function reversed (not included in the
code).

Any ideas as to what is causing this? Is it a compiler glitch, or a user
glitch :-)

Thanks

Olly

#include "stdafx.h"
#using <mscorlib.dll >

using namespace System;

public __gc class DriveClass
{
public:

void QueryPositionsF orward(Object* AxisList __gc[], double (__gc *
Positions) __gc[]){}
void QueryPositionsR everse(double (__gc * Positions) __gc[], Object*
AxisList __gc[]){}

};
Nov 17 '05 #1
2 2571
microsoft wrote:

void QueryPositionsF orward(Object* AxisList __gc[],
double (__gc * Positions) __gc[]){}
void QueryPositionsR everse(double (__gc * Positions) __gc[],
Object* AxisList __gc[]){}


If you're trying to get something similar to a C# API, you don't want to
have an array of pointers to value types. double is a value type, so you
just want a plain array of them. Here's the code I would suggest:

void QueryPositionsF orward(Object* AxisList __gc[],
double Positions __gc[]);
void QueryPositionsR everse(double Positions __gc[],
Object* AxisList __gc[]);

Hope that helps!

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Nov 17 '05 #2
Thanks for replying Brandon, but the value array parameter is a ref
parameter, so does need the pointer. Sorry I didn't explain that.

I have found more information. The following example fails to compile with
the error : 'Positions' : missing storage-class or type specifiers. Now the
way to fix it? remove the explicit __gc from the * in the second parameter!
Note that the explicit __gc works for the first parameter, and also the
pointer is (and must be?) a gc pointer. That is definately a compiler error.

Olly

#include "stdafx.h"
#using <mscorlib.dll >
using namespace System;

public __gc class DriveClass
{
public:

void QueryPositionsF orward(Object __gc* AxisList __gc[], double (__gc *
Positions) __gc[]){}

};

"Brandon Bray [MSFT]" <br******@onlin e.microsoft.com > wrote in message
news:uh******** ******@tk2msftn gp13.phx.gbl...
microsoft wrote:

void QueryPositionsF orward(Object* AxisList __gc[],
double (__gc * Positions) __gc[]){}
void QueryPositionsR everse(double (__gc * Positions) __gc[],
Object* AxisList __gc[]){}


If you're trying to get something similar to a C# API, you don't want to
have an array of pointers to value types. double is a value type, so you
just want a plain array of them. Here's the code I would suggest:

void QueryPositionsF orward(Object* AxisList __gc[],
double Positions __gc[]);
void QueryPositionsR everse(double Positions __gc[],
Object* AxisList __gc[]);

Hope that helps!

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.

Nov 17 '05 #3

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

Similar topics

0
1157
by: Richard | last post by:
I've created a __gc Array of ManualResetEvents seeing as this managed C++ and .NET is still new to me I'll try and explain. Each instance of one of my classes is going to require a pointer to one of these array elements. stepping through the assignment function it seems to work fine, but the next time I access the object from one of class' methods the value is undefined. How to I get it to stay?
19
2857
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type > >pointer-to-array-of-size-N-of-type-T (which is fine) and not having type > >array-of-size-N-of-type-T (with some exceptions, which is curious). > > So far > >the consensus seems to be that while everyone is aware of this no one knows
3
3393
by: NigelW | last post by:
Clarification needed please. If I compile a C++ program with the /clr option inpsection of the resulting assembly with ILDASM shows MSIL even for methods in classes for which I have not specified garbage collection with __gc. Am I correct in thinking there is really two kinds of managed (i.e. MSIL) code from C++, that which uses garbage collection and that which does not?
4
1174
by: TJH | last post by:
hi there im new to develop in .net, and i keep getting this compiler error "cannot perform pointer arithmetic on __gc pointer" when i try: some_object->array = something; Thanks :) Toke Jansen
4
1679
by: Tom | last post by:
Does anyone know if the 2005 version of C++.NET will support the traditonal C-style way of initializing arrays at the declaration? . -- Tom
3
1220
by: ravenous.wolves | last post by:
I'm trying to create a template function to convert from a vector of Es, to a managed array of Es. I want this to work with std::vector, or any other type that implements the call requirements of this function. I get the following error on this code: error C2143: syntax error : missing ')' before '<' template<typename T, typename E> E ToManaged( T<E> const & crUnmanagedVec ) __gc {
5
1101
by: TT (Tom Tempelaere) | last post by:
Hey everyone, If I am writing a .NET library using managed C++, when exactly do I have to decorate a pointer with the __gc decorator? Thanks, -- Tom Tempelaere.
8
1202
by: Peter Oliphant | last post by:
While it does look like 2005 does use a better syntax in general for garbage collection than 2003, here is something I think went the other way. arrays. Do people really think that: array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100); is a better syntax than: MyClass* MyArray __gc = new MyClass* __gc ;
0
972
by: John Gardner | last post by:
Hello I've got some managed C++ and I would like to do something like this: Int16 data1 __gc = {1, 2, 3, 4, 5}; Int16 data2 __gc = {2,3,4,5,6}; Int16 bigArr __gc; bigArr->Add(data1); bigArr->Add(data2);
0
10490
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10243
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.