how to implement interface with argument "int (__gc*) __gc[]"

K

kchui

I have a C# interface as:
public interface IBar{
void TestParam(ref StringCollection a, ref int [] b);
}

And I need to implment it in Managed C++, and I try to implement it as:

public __gc class Foo : public IBar
{
public:
virtual void ITestParam::TestParam(StringCollection __gc* __gc* a,
int (__gc*) b __gc[])
{
}
}

The complier complains that:
error C2146: syntax error : missing ')' before identifier 'b'.

I try a lot of different options, putting b in different position, and
just could not get it right. Any idea?

I realize that the problem is with the second parameter "ref int [] b"
cos if I took it out it just works.
 
K

kchui

Got a cut and paste error, I mean:

virtual void IBar::TestParam(StringCollection __gc* __gc* a,
int (__gc*) b __gc[])

but not:

virtual void ITestParam::TestParam(StringCollection __gc* __gc* a,
int (__gc*) b __gc[])


Thanks for any suggestion.
 
K

KCHUI

Thanks.
Yes, using your prototype seems to compile. But when I use the object
browser to look up the interface function TestParams, it indeed shows
as:

TestParams(StringCollection __gc* __gc*, int (__gc*) __gc[]);

That's how I tried to implment it as such. Anyway, without the 3 __gc
qualifier seems to make it compile, but does it mean that they are not
gc pointers?
 
S

Sebastian Dau

Hi,
TestParams(StringCollection __gc* __gc*, int (__gc*) __gc[]);
That's how I tried to implment it as such. Anyway, without the 3 __gc
qualifier seems to make it compile, but does it mean that they are not
gc pointers?

As I already indicated:

http://msdn.microsoft.com/library/d...gedextensionsforcfrequentlyaskedquestions.asp

there you'll find:

// This makes the function compliant with the common language
// specification (usable in C# and Visual Basic).
void Function7( Byte (*theArray) [] )
{
*theArray = new Byte[ 123 ];
}You so tell the compiler to take a managed reference pointer to a managed
array.Just don't wonder about the systax... as you might know, managed C++
designer drovethis language extensions to another inconvenient level.
C++/CLI will do better!Greetings, Sebastian Dau
 
K

KCHUI

Thanks for the clarification. I read the article you mentioned and
thought the same. But just need some experts like you to reinforce the
idea.

This new syntax, do's and don'ts, for managed c++ is quite cumbersome.
I guess I just have to play with it more.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top