A
Andrew Falanga
Hi,
In an earlier post, I was wondering why I can't compile unsafe code
*EVEN* when the, "Allow unsafe code," check box is checked. I'm still
working on that one. However, the whole problem can be averted if
someone here can explain how I might assign a value to memory pointed
to by an IntPtr object. Using the language that I know (C++) to
illustrate, this is what I want to do with an IntPtr object:
int *pInt = new int;
*pInt = 5;
My C# code is:
IntPtr dataSize = Marshal.AllocHGlobal(sizeof(int));
dataSize = ???????
So how do I assign a value to the memory just allocated?
This particular parameter is being passed to a p/invoke call and is an
in/out parameter. So far, using a standard C# int object and
referencing it as an "out" object in the definition of the p/invoke
function seems to be producing some undesired behavior. That's the
background as to why I need to do this.
I appreciate any help,
Andy
In an earlier post, I was wondering why I can't compile unsafe code
*EVEN* when the, "Allow unsafe code," check box is checked. I'm still
working on that one. However, the whole problem can be averted if
someone here can explain how I might assign a value to memory pointed
to by an IntPtr object. Using the language that I know (C++) to
illustrate, this is what I want to do with an IntPtr object:
int *pInt = new int;
*pInt = 5;
My C# code is:
IntPtr dataSize = Marshal.AllocHGlobal(sizeof(int));
dataSize = ???????
So how do I assign a value to the memory just allocated?
This particular parameter is being passed to a p/invoke call and is an
in/out parameter. So far, using a standard C# int object and
referencing it as an "out" object in the definition of the p/invoke
function seems to be producing some undesired behavior. That's the
background as to why I need to do this.
I appreciate any help,
Andy