By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

How to convert System.Array to IntPtr

P: n/a
Hello,
I have a question confused me a long time.
I am working on DirectDraw .NET a while.
And I want to copy data to surface, but I found Surface.Lock return
System.Array.
I tried to cast it to byte[],byte[,], but in vain( It will crash without any
exception).

Before I saw somebody said he used unsafe code to slove the problem on
newsgroup, but without any sample codes.

Can anyone give me some suggestion or ways to slove it? thanks a lot.

Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
zishen,

If you want to get the pointer to an array, you can do this:

// Unsafe code.
unsafe
{
// Fix the pointer to the array. Assume array is the variable and T is
the type of the array.
fixed (T* pArray = array)
{
// pArray now has the pointer to the array. You can get an IntPtr
by casting to void, and passing that in.
IntPtr intPtr = new IntPtr((void *) pArray);
}
}

That should work.

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

"zishen yan" <zishen ya*@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
Hello,
I have a question confused me a long time.
I am working on DirectDraw .NET a while.
And I want to copy data to surface, but I found Surface.Lock return
System.Array.
I tried to cast it to byte[],byte[,], but in vain( It will crash without
any
exception).

Before I saw somebody said he used unsafe code to slove the problem on
newsgroup, but without any sample codes.

Can anyone give me some suggestion or ways to slove it? thanks a lot.

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.