473,396 Members | 1,894 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,396 software developers and data experts.

return Struct from managed C++ to c#

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();

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
Feb 1 '06 #1
3 2279
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();

--
Tomas Restrepo
to****@mvps.org
http://www.winterdom.com/
Feb 1 '06 #2
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?
"Tomas Restrepo (MVP)" wrote:
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();

--
Tomas Restrepo
to****@mvps.org
http://www.winterdom.com/

Feb 1 '06 #3
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.
--
Tomas Restrepo
to****@mvps.org
http://www.winterdom.com/
Feb 1 '06 #4

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

Similar topics

8
by: Mike | last post by:
The following struct, DataStruct, is only part of a larger one that contains additional fields and arrays. I need the explicit layout because this struct is really a union, where some of the...
7
by: Urs Wigger | last post by:
In a C++ project, I have the following struct definition: struct GridModeDataT { double dVal1; double dVal2; double dVal3; long ...
8
by: Ben Terry | last post by:
What's the most efficient way to transfer data from a byte to a struct? The struct is rather complex--contains other structs as well as byte members. I've tried to use Marshal.Copy and an IntPtr...
5
by: Cybertof | last post by:
Hello, Is it possible to convert a VB6 Array of Struct to a C# Array Of Struct ? The test context is a C# application calling a VB6 ActiveX DLL Function using UDT (User Defined Type) and...
0
by: nygiantswin2005 | last post by:
I would like to know how do I pass a pointer to a struct from managed code to unmanaged code. For example if I create structure like this in managed code. StructLayout( LayoutKind.Sequential,...
2
by: symbol | last post by:
I am having this problem in a managed c++ DLL which mixes managed and unmanaged C/C++ code. I tried to assign value to a struct array nested in another struct. but I can only write to the first...
1
by: symbol | last post by:
I am having this problem in a managed c++ DLL which mixes managed and unmanaged C/C++ code. I tried to assign value to a struct array nested in another struct. but I can only write to the first...
4
by: haitao.song | last post by:
Hi, As it is always stated that value type is allocated on stack, while reference types are on managed heap. How about the struct with string members? stuct A { string str; } String type is...
1
by: DaTurk | last post by:
I'm having an issue converting an unmanaged struct to a CLI managed struct. It's a value struct and this cannot be changed. public value struct UpdateItem { public: System::String ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
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,...

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.