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

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 QueryPositionsForward. When reversing
the parameters illustrated by function QueryPositionsReverse, 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 QueryPositionsForward(Object* AxisList __gc[], double (__gc *
Positions) __gc[]){}
void QueryPositionsReverse(double (__gc * Positions) __gc[], Object*
AxisList __gc[]){}

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

void QueryPositionsForward(Object* AxisList __gc[],
double (__gc * Positions) __gc[]){}
void QueryPositionsReverse(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 QueryPositionsForward(Object* AxisList __gc[],
double Positions __gc[]);
void QueryPositionsReverse(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 QueryPositionsForward(Object __gc* AxisList __gc[], double (__gc *
Positions) __gc[]){}

};

"Brandon Bray [MSFT]" <br******@online.microsoft.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
microsoft wrote:

void QueryPositionsForward(Object* AxisList __gc[],
double (__gc * Positions) __gc[]){}
void QueryPositionsReverse(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 QueryPositionsForward(Object* AxisList __gc[],
double Positions __gc[]);
void QueryPositionsReverse(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
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...
19
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 >...
3
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...
4
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
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
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...
5
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
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: ...
0
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);...
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.