472,353 Members | 1,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Marshal a class partially

Hi.

Is is possible to mark a class-member-variable to avoid its marshaling?

[StructLayout(LayoutKind.Sequential)]
class MyClass
{
int i_;
IntPtr point_;

object obj; // this should not be marshaled
}

TIA.
Marco.

Nov 24 '05 #1
4 1468
Use [NotSerialized] attribute.

Nov 24 '05 #2
Thanks Tasos

but testing your suggestion with the following code it seems wrong:

//

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NotMarshal
{
class Program
{
[StructLayout(LayoutKind.Sequential)]
struct MyStruct
{
int i;
int j;
int k;
}

[StructLayout(LayoutKind.Sequential)]
struct MyStruct1
{
int i;
[NonSerialized]
int j;
int k;
}

[StructLayout(LayoutKind.Sequential)]
struct MyStruct2
{
int i;
int k;
}

static void Main(string[] args)
{
System.Console.WriteLine("SizeOf " + typeof(MyStruct).Name
+ " = " + Marshal.SizeOf(typeof(MyStruct)));
System.Console.WriteLine("SizeOf " + typeof(MyStruct1).Name
+ " = " + Marshal.SizeOf(typeof(MyStruct1)));
System.Console.WriteLine("SizeOf " + typeof(MyStruct2).Name
+ " = " + Marshal.SizeOf(typeof(MyStruct2)));
}
}
}

// output

SizeOf MyStruct = 12
SizeOf MyStruct1 = 12
SizeOf MyStruct2 = 8

sizeof MyStruct1 has to be 8.

Nov 24 '05 #3
>Is is possible to mark a class-member-variable to avoid its marshaling?

No. Can't you just separate the members to different types?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 24 '05 #4
it's what I did.

Thanks.

Nov 25 '05 #5

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

Similar topics

3
by: syd | last post by:
Hello all, In my project, I have container classes holding lists of item classes. For example, a container class myLibrary might hold a list of...
7
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
9
by: Angel | last post by:
Hi again, I'm trying to call functions from a proprietary DLL but it's turned out to be more difficult than I thought. I have this W32.DLL which...
6
by: SB | last post by:
I feel dumb to ask because I bet this is a simple question... Looking at the code below, can someone please explain why I get two different...
1
by: dhornyak | last post by:
I have been banging my head against the wall for a while now, and can't seem to id the problem. I've been through a ton of posts and the code...
6
by: william.thorpe.b | last post by:
I have recently switched from VS2003 to VS2005 and at the same time from V1 to V2 of the .NET Compact Framework. The target is a Windows CE 5.0...
8
by: Rahul | last post by:
Hi, Is there a way to partially specialize only a member function of a template class (not the whole class). e.g. template <typename A,...
2
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the...
0
by: xrxst32 | last post by:
Hello there, I have some doubts about the best practice for using COM automation, the Runtime Callable Wrapper (RCW) and Marshal.ReleaseComObject....
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.