473,396 Members | 2,018 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.

IntPtr to fixed bytes array

hello

I wonder if there is any possibility to create IntPtr type to point to bytes array? I tried Marshal.Copy() but mem address was changing all the time. I have code like this :

Expand|Select|Wrap|Line Numbers
  1.  
  2. Random rnd = new Random();
  3.             data = new Byte[100];
  4.             rnd.NextBytes(data);
  5. unsafe
  6.             {
  7.                 fixed( byte*  wsk = data)
  8.                 {
  9.                     IntPtr unmanagedPointer = wsk;
  10.                 }
  11.             }
  12.  
of course it doesn't work :) but that code show what im trying to do. Can anyone tell me what should I do?
Dec 8 '10 #1
1 3275
Raj K
9
Ideally you should not assume the fixed address of managed code if you think in terms of native code.
What you can do is to allocate memory using Marshal then copy the content of byte array to the allocated memory then point the IntPtr to that memory
Dec 8 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jeroen Ceuppens | last post by:
I created new bitmap file, bitmapdata, now a want the pixeldata that are in the array bytes put into the bmpData, what should I change in the code unsafe? there is something wrong with p =...
1
by: Geoffrey | last post by:
Hello, I have one array of Bytes , and I want to add some Bytes at the start of the array. Is it possible to move all the bytes of the array to right , so I can insert my Bytes like Bytes, ......
1
by: O.B. | last post by:
In the example below, I'm trying to convert a fixed byte array to a string. I get an error about needing to use "fixed" but I have no clue where to apply it. Help? using System; using...
0
by: ambeer | last post by:
Hello, i have created the struct: #region PacketStructures struct MainPacket { HeaderData headerData; public byte moduleType; ...
1
by: shofu_au | last post by:
Hi Group, I am trying to define a class that has a fixed size array of a structure containing a fixed size array of a structure. I am using System.Runtime.InteropServices and trying to define...
0
by: kishor14 | last post by:
I need an example of how to marshal a structure that has an array of another structures as a member. An example as mentioned below public struct strcutdata { ...
0
by: Piotrekk | last post by:
Hi I have an dword array returned by send message with TBM_GETPTICS Message. Thus i need to convert IntPtr to managed block of memory ( Int32 because od dword ). I tried saveral ways but it...
2
by: =?Utf-8?B?U3VzaGlTZWFu?= | last post by:
Hello, I have a question. byte network = new byte; And I know what in this byte array in position from 4 to 8 it is long value, and from 10 to 12 is it ushort type. I need do something like...
3
by: kaffekopp | last post by:
Hi, Since this is the first time for me using fixed size arrays, i would appreciate some guidance to solve this question. First of all, these structures are to be used: struct song { char ...
2
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...
0
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...

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.