return Struct from managed C++ to c#

G

Guest

Hello,
How can I return a struct type e.g. System::Drawing::point from a managed
c++ class to a C# assembly?

When I have the declaration of the managed C++ class's member function as
System::Drawing::point __gc* GetData();

then the C# assembly can't see it, presumably because System.Drawing.Point
is a struct rather than a class. The managed c++ library compiles OK, it's
just the C# assembly doesn't see that method with that return value.

It works ok when I use a class such as System.String.

Is there some part of the syntax I'm missing?

Any help much appreciated

Thanks
 
T

Tomas Restrepo \(MVP\)

BJT,
Hello,
How can I return a struct type e.g. System::Drawing::point from a managed
c++ class to a C# assembly?

When I have the declaration of the managed C++ class's member function as
System::Drawing::point __gc* GetData();

You're returning a managed pointer to the struct, not the struct itself. How
about:

System::Drawing::point GetData();
 
G

Guest

I thought I'd tried that and it didn't work, but I'll give it another go.

Do you know that to be the correct syntax?
 
T

Tomas Restrepo \(MVP\)

BJT,
I thought I'd tried that and it didn't work, but I'll give it another go.

Do you know that to be the correct syntax?

Point is a value type, and you want to return the value itself, not a
pointer to it, so yes, it should be. What's the entire method code (or at
least the relevant sections)? Perhaps you have another problem there.
 

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