473,385 Members | 2,180 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,385 software developers and data experts.

cast byte[] to various managed types

I have a byte[] returned from an unmanaged dll. If I was in c/c++ I would
do something like this:

void* pData; // a pointer to a struct with various types

int i;
int* i = &i;
*i = *pData;

or something like that, it's been awhile...

but in c#, I can't find the solution. I have looked at Convert.ToInt32 but
it will only take a single byte type which isn't enough.

I tried using unsafe but didn't find success.

I have google and googled, but nothing is coming up for me solution. I
found one article that sounded promising utilizing BinaryFormatter, but
wasn't able to get it to work.

Anyone have an example how to case an array of bytes to various managed
types?

Thanks,
Steve
Feb 25 '06 #1
1 1413

"sklett" <sk****@mddirect.com> wrote in message
news:uT**************@TK2MSFTNGP14.phx.gbl...
I have a byte[] returned from an unmanaged dll. If I was in c/c++ I would
do something like this:

void* pData; // a pointer to a struct with various types

int i;
int* i = &i;
*i = *pData;

or something like that, it's been awhile...

but in c#, I can't find the solution. I have looked at Convert.ToInt32
but it will only take a single byte type which isn't enough.


Look at the BitConverter class, it'll probably let you do most of what you
need to do(You might have some endianess problems, in which case Jon Skeet's
EndianessBitConverter[1] might be of use).

1. http://www.yoda.arachsys.com/csharp/miscutil/
Feb 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pablo Gutierrez | last post by:
I have a C# method that reads Binary data (BLOB type) from a database and returns the data an array of bytes (i.e byte outbyte = new byte;). The BLOB column is saved into the database by a C...
8
by: Ben Terry | last post by:
What's the most efficient way to transfer data from a byte to a struct? The struct is rather complex--contains other structs as well as byte members. I've tried to use Marshal.Copy and an IntPtr...
17
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this...
1
by: Drew | last post by:
Does this return the array by value or reference? Because of DotNet's memory handling, I don't know how I could figure this out... Is there a way? System::Byte...
0
by: BobTheHacker | last post by:
I have a c# class library that I call to centralize some code amongst projects. It returns an arraylist back to the calling function that contains class data. Anyway when I call it I can receive it...
6
by: Tim | last post by:
I'm trying to co-erce a __gc array of Byte to a __nogc pointer to char to pass to a native function call in a bit of managed c++ code like this: Byte field __gc = dynamic_cast<Byte...
5
by: Robin Tucker | last post by:
I need to marshal an IntPtr (which I've got from GlobalLock of an HGLOBAL) into a byte array. I know the size of the array required and I've got a pointer to the blob, but I can't see how to copy...
6
by: Rain | last post by:
Im a newbie and i need help.. would appreciate any help at all... I need to make a method that accepts a 34 bytes data and inside the method i need to get the 2nd, 3rd, 4th or any of the byte...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.