473,396 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to convert System.Array to IntPtr

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
1 25405
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Abraham Lopez | last post by:
Hi.. Is there a way to convert a System.Array to XML... If you know thanks very much... if you don't... Please do not respond stupid things like " Yes -- many ways."
4
by: Janus Knudsen | last post by:
Hello Im getting an error when I try to convert like this: string arrDSN; objDSN.GetDataSourceList(arrDSN) And the error: Argument '1': cannot convert from 'string' to 'ref System.Array'
0
by: jmrieman | last post by:
first off, I am an IT pro trying to dust off the cobwebs of programming in a Master degree program so please be nice:) I am trying to pass a system.array object by reference to a procedure (or...
15
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
1
by: m830266 | last post by:
I'm trying to use the APAX serial I/O control (www.turbocontrol.com/AProZilla.htm) in a VB.NET project and I'm having trouble with its 'data received' events. The data is supplied by APAX as a...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
4
by: viks | last post by:
Hi guys I need little help here . I want to convert 'System::Object __gc * array ' to 'float array' Lets say I have object Reader with method Send ,it returns a variant that contains a...
3
by: clawton | last post by:
Hi All - I've got a 3rd party COM object that returns an array of bytes that are a TIFF image. After adding the reference to the com object to my solution the C# signature for the method is...
2
by: Fred Mellender | last post by:
I am trying to use reflection to output the fields (names and values) of an arbitrary object -- an object dump to a TreeView. It works pretty well, but I am having trouble with generic lists,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.