.NETGURU
How do I Get Around Using Copymemory?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.faqs.

Post a new message to this list...

Alex
I have been using VS.net now for a while mainly using ASP.Net however I feel
ready to start upgrading applications to VS.Net.

However most of my previous VB applications used Copymemory regularly to do
the following things

1. Join and split variabes such as long to 2 integers and back again
2. converting Binary data in to User defined type stuctures and back again
3. pack various variables, strings etc. into byte arrays which i could read
and write to and from files.

I like managed code and would like to avoid unsafe code in c#.

I regularly save structures to and from binary files and I want to be able
to convert these things. I have found a number of workarounds for most
things however this is an area I need to conquer before can convert the
applications.

Another thing I would do was copy a stream of variables into a byte array
and then write it to file and then later read it from the file into a
bytearray and pull out the variables using a pointer to each part of the
byte array.

also Does anyone know any way to split variables and combine them e.g. 2
bytes into a short.
I know that this can be done with masks however I am struggling to do this
efficiently since my maths in this are is a bit lacking and I am getting
overflows when working with signed variables.

Any help with the above would be great

Thanks Alex

Reply to this message...
 
    
Cablewizard
Alex,

I primarily use VB.Net and not C#, but the answer is basically the same...
For all your Byte level manipulations, explore the System.BitConverter class.
While it may not handle full UDT's (Structures) as easily as CopyMemory, it will
give you pretty much everything you need.
For Text manipulations, explore the System.Text.Encoding class.
Subclasses allow you do do most things text related as in streaming to bytes and
back.
Additionally, you can choose which encoding to use; ASCII, UTF, Unicode, etc.

For example, say you have a Byte array (myBytes) with 2 bytes to represent a
Short (myShort) at index 2 in the array.
myShort = System.BitConverter.ToInt16(myBytes, 2)

Hope this helps,
Gerald

"Alex" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.BitConverter
System.Text.Encoding




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification