PC Review


Reply
Thread Tools Rate Thread

How to convert between an IntPtr and a byte[]?

 
 
Dave
Guest
Posts: n/a
 
      13th Aug 2003
We are writing some code to interface to a DLL. The DLL
has a callback method that returns the address of a byte
buffer and the buffer length. I have defined the byte
pointer as an IntPtr.

How do I convert between the IntPtr and my managed byte[]
that I want to copy the data into???

-dave
 
Reply With Quote
 
 
 
 
Michel Gallant
Guest
Posts: n/a
 
      13th Aug 2003
Better asked in microsoft.public.dotnet.framework.interop, but:

Use the Marshal methods:

IntPtr pData = ....
byte[] buffdata = new byte[size];
Marshal.Copy(pData, buffdata, 0, size);


Note that it is often easier to proto-type with a [In, Out] byte[] data
then using an IntPtr.

- Michel Gallant
MVP Security

"Dave" <(E-Mail Removed)> wrote in message news:020501c361b3$5088f8e0$(E-Mail Removed)...
> We are writing some code to interface to a DLL. The DLL
> has a callback method that returns the address of a byte
> buffer and the buffer length. I have defined the byte
> pointer as an IntPtr.
>
> How do I convert between the IntPtr and my managed byte[]
> that I want to copy the data into???
>
> -dave



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pinvoke double[] to Intptr , passing double as IntPtr ?? Sagaert Johan Microsoft C# .NET 4 22nd Nov 2008 12:10 AM
ExtractIconEx(iconFullPath, -1, IntPtr.Zero, IntPtr.Zero, 0) does what??? Frank Microsoft C# .NET 0 28th Jan 2007 04:45 PM
Cast between a function pointer and IntPtr Abra Microsoft C# .NET 4 19th Jan 2006 05:03 PM
IntPtr to IntPtr Copy =?Utf-8?B?UWluZ2RvbmcgWi4=?= Microsoft C# .NET 1 17th Feb 2005 01:19 AM
Cannot convert to System.IntPtr Daisy Microsoft C# .NET 4 29th Nov 2003 11:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:41 AM.