473,800 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is Marshaling?

VM
What's marshalling? I've had to use it extensively for a project but I don't
know what it means. I tried to look for a definition in the Internet but I
couldn't find anything that would explain what it is.
Is converting a C-style struct to a C# class (or struct) marshalling? And
what about the function exports? Are those Marshalling too?

Thanks for your help and thanks for helping me with the Dll exports (the
several messages I posted in NG). Everything worked great.

My last step is to convert some C-structs (with embedded structs and members
of type struct) into classes. But I won't be working on that yet.
Nov 15 '05 #1
5 96499
Marshaling is the act of taking data from the environment you are in and
exporting it to another environment. In the context of .NET, marhsaling
refers to moving data outside of the app-domain you are in, somewhere else.

When you work with unmanaged code, you are marshaling data from your
managed app-domain to the unmanaged realm. Also, when transferring data
between app-domains (to another application, on the same or another
machine), you are also marshaling data from your app-domain, to another
app-domain.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"VM" <vm@none.com> wrote in message
news:Oo******** ******@TK2MSFTN GP11.phx.gbl...
What's marshalling? I've had to use it extensively for a project but I don't know what it means. I tried to look for a definition in the Internet but I
couldn't find anything that would explain what it is.
Is converting a C-style struct to a C# class (or struct) marshalling? And
what about the function exports? Are those Marshalling too?

Thanks for your help and thanks for helping me with the Dll exports (the
several messages I posted in NG). Everything worked great.

My last step is to convert some C-structs (with embedded structs and members of type struct) into classes. But I won't be working on that yet.

Nov 15 '05 #2
VM
Thanks. So is recreating the structs into C#-readable structs (class or
struct) marshalling?

And what's unamanaged code? I've heard that code with pointers is unmanaged
code, or C code is unmanaged code. But why is a class managed code (if that
statement is true) hile other code is unmanaged?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:#h******** ******@TK2MSFTN GP09.phx.gbl...
Marshaling is the act of taking data from the environment you are in and exporting it to another environment. In the context of .NET, marhsaling
refers to moving data outside of the app-domain you are in, somewhere else.
When you work with unmanaged code, you are marshaling data from your
managed app-domain to the unmanaged realm. Also, when transferring data
between app-domains (to another application, on the same or another
machine), you are also marshaling data from your app-domain, to another
app-domain.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"VM" <vm@none.com> wrote in message
news:Oo******** ******@TK2MSFTN GP11.phx.gbl...
What's marshalling? I've had to use it extensively for a project but I

don't
know what it means. I tried to look for a definition in the Internet but I couldn't find anything that would explain what it is.
Is converting a C-style struct to a C# class (or struct) marshalling? And what about the function exports? Are those Marshalling too?

Thanks for your help and thanks for helping me with the Dll exports (the
several messages I posted in NG). Everything worked great.

My last step is to convert some C-structs (with embedded structs and

members
of type struct) into classes. But I won't be working on that yet.


Nov 15 '05 #3
> Thanks. So is recreating the structs into C#-readable structs (class or
struct) marshalling?
Yes, it's one form of marshaling. As people said, marshaling is serializing
or transforming types over the wire or some boundary. COM had marshaling
when you went out of one apartment into a non-compatible apartment or across
the wire to another machine. When dealing with COM Interop, .NET uses
Interop Marshaling between COM data types and .NET CLR types.
And what's unmanaged code? I've heard that code with pointers is
unmanaged

code, or C code is unmanaged code. But why is a class managed code (if
that
statement is true) hile other code is unmanaged?


Unmanaged code is simply all code pre .NET. It is all code NOT compiled to
operate under .NET's runtime, the CLR. Unmanaged code is code compiled and
linked natively and has no knowledge of the CLR. Unmanaged code can be
native C++ with pointers, or C, or VB 6, or Delphi, etc. It is everything
not managed by the CLR. In the CLR, code is compiled into IL + metadata into
assemblies and then those assemblies are JITed into assembly language
instructions while called. It is the metadata throughout that allows managed
code to be managed, managed by the CLR. The CLR can control the type
definitions and boundaries (enforce CTS type definitions), control memory
through automatic management of data via the garbage collector, and provide
CAS security among other benefits. So a class is managed code IF compiled
with a .NET compiler and controlled by the CLR whereas "other code is
unmanaged" because it is compiled without a .NET compiler and uses the
unmanaged heap for memory and knows nothing of the CLR.

This is the answer to your question but I can go deeper if you want.
Essentially, both systems produce a Windows PE format file in the form of a
DLL or EXE. The huge difference is that in .NET, that PE file is called an
assembly and has different header. It also contains IL + metadata. All .NET
compilers are REQUIRED to emit IL + metadata. The metadata fully describes
all types in terms of CTS types. The metadata allows managed code to be
called "self-describing." When that assembly is loaded, and the types used,
the CLR JIT's the IL for the called method and replaces that section of IL
with the native assembly language. The IL is *never* interpreted but
provides a common platform-independent, language-independent standard form.
Because of all this, the CLR can manage the types and provide it's services.

--
-----
Sam Gentile
Microsoft MVP - C#/.NET
..NET Blog http://samgentile.com/blog/

Please do NOT contact me directly but respond to
the newsgroup instead.
---------
"VM" <vm@none.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Thanks. So is recreating the structs into C#-readable structs (class or
struct) marshalling?

And what's unamanaged code? I've heard that code with pointers is
unmanaged
code, or C code is unmanaged code. But why is a class managed code (if
that
statement is true) hile other code is unmanaged?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in
message news:#h******** ******@TK2MSFTN GP09.phx.gbl...
Marshaling is the act of taking data from the environment you are in

and
exporting it to another environment. In the context of .NET, marhsaling
refers to moving data outside of the app-domain you are in, somewhere

else.

When you work with unmanaged code, you are marshaling data from your
managed app-domain to the unmanaged realm. Also, when transferring data
between app-domains (to another application, on the same or another
machine), you are also marshaling data from your app-domain, to another
app-domain.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"VM" <vm@none.com> wrote in message
news:Oo******** ******@TK2MSFTN GP11.phx.gbl...
> What's marshalling? I've had to use it extensively for a project but I

don't
> know what it means. I tried to look for a definition in the Internet
> but I > couldn't find anything that would explain what it is.
> Is converting a C-style struct to a C# class (or struct) marshalling? And > what about the function exports? Are those Marshalling too?
>
> Thanks for your help and thanks for helping me with the Dll exports
> (the
> several messages I posted in NG). Everything worked great.
>
> My last step is to convert some C-structs (with embedded structs and

members
> of type struct) into classes. But I won't be working on that yet.
>
>



Nov 15 '05 #4
Sam,

From the perspective of a .NET developer, managed code does in fact equal
..NET code, and unmanaged code is all code that does not run under the CLR.

However, Java bytecode is often referred to as "managed code" as well. By
this more generic definition, managed code is any code that is run in a
managed environment that controls security access and access to resources.
That managed environment might be .NET's Common Language Runtime, Java's
bytecode interpreter, or something else. It is not enough for the code to
require a supporting runtime; VB6 or FoxPro executables, for example, are
not "managed" in this sense. A support library full of routines is
passively called by such code; but unlike a suport library, a manged
environment may refuse application an request if it violates security
protection levels or accesses forbidden resources. In order to be able to
determine whether or not to honor requests, the application code must be
self-describing; hence the other requirement to call an execution
environment "managed."

So, generically, managed code (1) contains some kind of meta-data to
describe itself to its runtime environment with (2) actively grants or
denies application requests based on the defined security configurations for
the application, and the machine and network the application is interacting
with.

--Bob

"Sam Gentile [MVP - C#/.NET]" <no****@nomail. com> wrote in message
news:u$******** ******@TK2MSFTN GP09.phx.gbl...
Thanks. So is recreating the structs into C#-readable structs (class or
struct) marshalling?


Unmanaged code is simply all code pre .NET.

Nov 15 '05 #5
You're right of course as I did this only from the Microsoft perspective and
not a general question (as I thought this is what the question referred to)

--
-----
Sam Gentile
Microsoft MVP - C#/.NET
..NET Blog http://samgentile.com/blog/

Please do NOT contact me directly but respond to
the newsgroup instead.
---------
"Bob Grommes" <bo*@bobgrommes .com> wrote in message
news:Op******** *****@TK2MSFTNG P11.phx.gbl...
Sam,

From the perspective of a .NET developer, managed code does in fact equal
.NET code, and unmanaged code is all code that does not run under the CLR.

However, Java bytecode is often referred to as "managed code" as well. By
this more generic definition, managed code is any code that is run in a
managed environment that controls security access and access to resources.
That managed environment might be .NET's Common Language Runtime, Java's
bytecode interpreter, or something else. It is not enough for the code to
require a supporting runtime; VB6 or FoxPro executables, for example, are
not "managed" in this sense. A support library full of routines is
passively called by such code; but unlike a suport library, a manged
environment may refuse application an request if it violates security
protection levels or accesses forbidden resources. In order to be able to
determine whether or not to honor requests, the application code must be
self-describing; hence the other requirement to call an execution
environment "managed."

So, generically, managed code (1) contains some kind of meta-data to
describe itself to its runtime environment with (2) actively grants or
denies application requests based on the defined security configurations
for
the application, and the machine and network the application is
interacting
with.

--Bob

"Sam Gentile [MVP - C#/.NET]" <no****@nomail. com> wrote in message
news:u$******** ******@TK2MSFTN GP09.phx.gbl...
> Thanks. So is recreating the structs into C#-readable structs (class or
> struct) marshalling?


Unmanaged code is simply all code pre .NET.


Nov 15 '05 #6

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

Similar topics

0
1894
by: Ash | last post by:
Hi, Has anyone ever tried using "COM marshaling" for cross- process communication? In particular, I am interested in cross-process marshaling between Managed Server and Unmanaged Client. There seems to be very little documentation/examples on this. I have a "Service" that needs to have a COM
3
2669
by: Nikolay Petrov | last post by:
Guys, please help. I am trying to make this work from at least 4 months. I am new to programming and some things are difficult to me, but I really need to make my project work. I can't find anything helpfull in internet for 4 months ;-( . Please someone who is more expirenced help me. I am trying to use the Terminal Server APIs There is as an API function WTSEnumerateSessions, which returns a WTS_SESSION_INFO custom structure n times....
3
3649
by: Rudy Velthuis | last post by:
Hello, Does anyone know how to create a struct that will marshal to the following C++ struct A, containing an array of the user defined String10 type: struct String10 { char SLen; char S;
1
2483
by: Nadav | last post by:
Hi I am about to write a performance crutial system, I am considering writing this system based on native COM or unmanaged C++ exposed as CLI, Now, I Wonder... does exposing a native code through CLI ( using a mixed mode DLL ) have any performance penalty? consider one Native C++ CLI assembly calling a methos od another CLI Native C++ Assembly, will there be any marshaling penalty, will there be any penelty at-all? is it possible to pass a...
2
3957
by: mirek | last post by:
Hi, I'm trying to import my old code to the .NET using managed wrappers. I've read "Managed Extensions for C++ Migration Guide" document and was trying to do what it stated in it. For example if my function takes mfc's CString I was converting it this way: char __pin* szUser = static_cast<char*>(Marshal::StringToHGlobalAnsi(sUser).ToPointer()); and pass szUser to the function.
1
2680
by: Bill Medland | last post by:
I am trying to do some P/Invoke custom marshaling and am looking for a little help on custom marshaling a value type. I am working based on Kate Gregory's "Arranging Custom Marshaling With P/Invoke", which is unfortunately in C++ with managed extensions; I am working in C#. As with Kate's example I want to marshal from a System.DateTime to a proprietary format. However I cannot figure out how to tell the system to box the DateTime. ...
10
11358
by: giddy | last post by:
hi , I' know what the StructLayoutAttribute does. I've seen it being used. But what does the Pack field do!? This is what MSDN says: Controls the alignment of data fields of a class or structure in memory. This field indicates the packing size that should be used when the LayoutKind.Sequential value is specified. The value of Pack must be 0,
1
2684
by: Frankie | last post by:
I have been learning about asynchronous method calls and I keep coming across this term, "marshal" and I would like to know what it means - specifically. AFAIKT, it means "send" but I suspect there is a bit more than that. Looking to online docs, MSDN talks about the System.Runtime.Interop.Marshal class - but I don't think that's relevant to what I'm seeing. Maybe it is... The following is an example of the sort of thing I've been...
0
1880
by: jpogorman | last post by:
Hello, I am trying to get c# custom marshaling working in a particular scenario but it does not appear to be working or not jumping into my marshaling class when I try to debug it. I am try to implement a performance improvement in the transfer of thousands of objects (ClientInfoDescriptor) over a remote call. The objects all have a model object (IDataDrivenModel) to describe them but there may only two or three model objects in total. These...
0
9550
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10250
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
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...
0
6811
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
5469
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
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2944
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.