473,747 Members | 3,014 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 25610
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.co m

"zishen yan" <zishen ya*@discussions .microsoft.com> wrote in message
news:BC******** *************** ***********@mic rosoft.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
12047
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
12333
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
1600
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 class) and keep getting the compile error "an object reference is required for the nonstatic field, method, or property... (you know the rest) .. please look at my code and tell me why my pass by reference is not working static void Main(string...
15
10833
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
3769
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 variant which appears to VB.NET as a System.Object. I want to convert this to a System.Array so that I can iterate over its elements. The VB6 usage is described at www.turbocontrol.com/TechTips/20020426.htm. If I try something similar in...
5
19599
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 having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return an Array instead of an ArrayList. Now I get the message when I try to run just my webservice...
4
6076
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 one-dimensional array of float value . I m trying to do something like this.
3
5461
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 something like this: System.Array Item.GetContent(); I need to save the bytes to a file that will be the tiff file...so when I
2
6159
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, like List<char>. What I have working is : Type type = newObj.GetType(); //newObj is what I'm trying to dump
0
8818
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9354
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9307
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9223
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8233
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6067
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4588
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4860
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.