473,769 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CLI ref structs. Is there any benefit to using it.

Hi,

I'm coding a layer into my application using CLI, between a unmanaged
and a c# layer. So, I have to marshal some unmanaged c++ structures
to structures usable in c#.

My solution was to marshal the unmanaged C++ structures to CLI ref
structs, these being usable in the c# layer. Why I did it this way is
I want all of the business logic in the CLI layer. Because he c#
layer is purely presentaion.

My question is, what is the point of using CLI ref structs?

Apr 19 '07 #1
6 8152
I'm coding a layer into my application using CLI, between a unmanaged
and a c# layer. So, I have to marshal some unmanaged c++ structures
to structures usable in c#.

My solution was to marshal the unmanaged C++ structures to CLI ref
structs, these being usable in the c# layer. Why I did it this way is
I want all of the business logic in the CLI layer. Because he c#
layer is purely presentaion.

My question is, what is the point of using CLI ref structs?
Hi,

the point of using ref structs is that they translate to classes with public
members on the C# side without the need for marshalling. As a result, you
can pass those structures to the C# side or to .NET methods.
If these structures do not leave the CLI side, there is no point to
marshaling them because C++/CLI is designed to use unmanaged structures and
classes without a problem. In that case, marshaling them to managed
stuctures is redundant.

--
Kind regards,
Bruno van Dooren MVP - VC++
http://msmvps.com/blogs/vanDooren
br************* *********@hotma il.com
Apr 20 '07 #2
On Apr 20, 1:50 am, "Bruno van Dooren"
<bruno_nos_pam_ van_doo...@hotm ail.comwrote:
I'm coding a layer into my application using CLI, between a unmanaged
and a c# layer. So, I have to marshal some unmanaged c++ structures
to structures usable in c#.
My solution was to marshal the unmanaged C++ structures to CLI ref
structs, these being usable in the c# layer. Why I did it this way is
I want all of the business logic in the CLI layer. Because he c#
layer is purely presentaion.
My question is, what is the point of using CLI ref structs?

Hi,

the point of using ref structs is that they translate to classes with public
members on the C# side without the need for marshalling. As a result, you
can pass those structures to the C# side or to .NET methods.
If these structures do not leave the CLI side, there is no point to
marshaling them because C++/CLI is designed to use unmanaged structures and
classes without a problem. In that case, marshaling them to managed
stuctures is redundant.

--
Kind regards,
Bruno van Dooren MVP - VC++
http://msmvps.com/blogs/vanDooren
bruno_nos_pam_v an_doo...@hotma il.com
I'm not sure I understand. Why wouldn't I just use a CLI class then.
What's the difference? Is there any real benefit though?

Apr 20 '07 #3
I'm not sure I understand. Why wouldn't I just use a CLI class then.
What's the difference? Is there any real benefit though?
Are you asking about "ref struct vs ref class" or "ref struct vs native
class" or "ref struct vs value struct"?

ref struct and ref class are related in the same way as native struct and
native class -- there is no runtime difference. The only thing affected is
that struct, ref struct, and value struct all start with implicit "public:"
and class, ref class, and value class all start with implicit "private:".
ref class and ref struct are both C++/CLI equivalents to C# struct, all
three generate a garbage collected pass-by-ref CLR type, and all three have
different default member visibility.
Apr 20 '07 #4
DaTurk wrote:
I'm not sure I understand. Why wouldn't I just use a CLI class then.
What's the difference? Is there any real benefit though?
C++/CLI -------C#
=============== =====
ref class -----class
ref struct ----class
value class ---struct
value struct --struct

The C++/CLI keyword "ref" always indicates a reference type (C# class),
while the "value" keyword always refers to a value type (C# struct).

What confuses you is that in C# class and struct mean completely
different things than in C++. In C++, the only difference between class
and struct is whether members are public or private by default. In C#,
on the other hand, a class is a reference type, and a struct is a value
type, and they have nothing to do with public vs private access.

Tom
Apr 20 '07 #5
Ben Voigt wrote:
ref class and ref struct are both C++/CLI equivalents to C# struct
I think you meant C# class.

Tom
Apr 20 '07 #6

"Tamas Demjen" <td*****@yahoo. comwrote in message
news:OT******** ********@TK2MSF TNGP05.phx.gbl. ..
Ben Voigt wrote:
>ref class and ref struct are both C++/CLI equivalents to C# struct

I think you meant C# class.
Yes indeed.

ref class and ref struct are both C++/CLI equivalents to C# class
value class and value struct are both C++/CLI equivalents to C# struct

Thanks for calling out my typo.
Apr 20 '07 #7

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

Similar topics

8
25915
by: Rick | last post by:
Hi, We all know that Java has classes but how about basic storage objects like structs? C and C++ have Structs, Pascal has Records, Visual Basic has Types etc. How about Java? Greetings, Rick
49
2835
by: Christopher J. Bottaro | last post by:
I find myself doing the following very often: class Struct: pass .... blah = Struct() blah.some_field = x blah.other_field = y ....
4
2010
by: news.microsoft.com | last post by:
Hi, I am using structs and am also using property accessors to access those private member fields... TO me this is a good way of handling them, but I find alot of people using direct access to the struct memebers, since structs is just a type similar to a class (with differences I know) why should I allow direct access like that... I looked at the Size and other parts on Control etc and I find its the same way by using property...
30
4273
by: stephen henry | last post by:
Hi all, I have a question that I'm having difficulty answering. If I have a struct: typedef struct my_struct_tag{ struct my_other_struct *other; } my_struct_tag
28
2205
by: codymanix | last post by:
Last night I had several thought about RAII and want to discuss a bit. Why doesn't CSharp support destructors in structs? Wouldn't that make RAII possible like in C++? When the struct goes out of scope, the dtor could be immediately be called (no GC needed). For that, you don't have to declare the whole File class as a struct (which would be not good for performance when File has a lot of data-members). Instead creating a thin wrapper...
3
1897
by: Chua Wen Ching | last post by:
Hi there, I had seen examples for classes, but i had no idea how to implement the same thing in struct. I am quite mix up! Which one is correct? Scenario: WForm.cs - the one that calls FileA.cs to access the structures FileA.cs - contains all structures
3
2848
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; } *arrays; It's supposed to be a structure containing an array of chars, an array of ints and an int. I declare functions like this : arrays *parseline(char *line, int N)
61
3781
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch (myBranch + x) = new Branch(i); // it doesn't x is a loop iterator, i is an int for the constructor to define an array. What am I doing wrong here.
29
2792
by: Dom | last post by:
I'm really confused by the difference between a Struct and a Class? Sometimes, I want just a group of fields to go together. A Class without methods seems wrong, in that it carries too much overhead (I think). A Struct seems more appropriate. At least it is what I would have used in other languages. But since a Struct *can* hold methods, I wander if I am saving anything. If not, why use it?
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8873
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...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
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
5310
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.