TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
bilnaad
NA
686
0
struct to IntPtr?
Nov 30 2004 2:18 PM
Hi all, Is there a way to create an IntPtr from a struct rather then this way? ----------------------------------------------- namespace csConsole { using System; using System.Runtime.InteropServices; struct Test { public int Value; public Test(int e) {Value = e;} public override string ToString() { return string.Format("Test.Value = {0}",Value); } } class MessageTest { public unsafe static IntPtr Get(Test* t) { IntPtr ptr = new IntPtr(t); Marshal.StructureToPtr(new Test(12345) ,ptr ,true); return ptr; } public static unsafe void Main() { Test* tPtr = stackalloc Test[1]; Test d = (Test)Marshal.PtrToStructure(Get(tPtr) ,typeof(Test)); Console.WriteLine(d); Console.Read(); } } } ----------------------------------------------- This way I need unsafe context and allocate space on the stack which is only usable in the methods scope. Is there another way of creating and maintaining IntPtrs? Thanks in advance
Reply
Answers (
0
)
Problems with System.Diagnostics.Process Class
About Real Life