Replacement of MoveMemory in VB.NET

Hello Folks,

I am converting VB.6 application to VB.NET 2005.During conversion I couldnt find the resplacement of API MoveMemory which is used in VB.6 application.

Is there anybody who has faced similar kind of problem or know how to solve it.

Thanking you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
You may not need MoveMemory.  What are you trying to accomplish in .NET 2005?   There might be an easier way without API calls.

ChiragDanechAuthor Commented:
Trying to copy Structure type to 2 dimensional array.

MoveMemory(VarPtrArray(2 dimensional Array), VarPtr(structureType), 4)

Its urgent . Can anybody reply me asap.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Bob LearnedCommented:
Ok, let's take a little wider view of your requirement.   What is the overall requirement?  How does this one little question fit into the grander scheme?  That is what I meant by it might be easier without API calls.  Maybe we could suggest a native .NET framework approach, if we knew what you were trying to convert.  It might be simpler than complex memory operations.

You can use the Marshal class to copy memory, but with the garbage collector, it gets a little messy, since you have to start think about handles and pinning memory.

ChiragDanechAuthor Commented:
I appriciate  your comments on it. But Its difficult to explain the whole thing. I have already converted 75 % of the VB application into VB.NET. I just stuck here on MoveMemory API. And as i have aleready mentioned my cleare intension what I need to do.
Bob LearnedCommented:
Here is an example of using the Marshal.Copy method from System.Runtime.InteropServices:

  Private Shared Function ByteArrayToInteger(ByVal byteArray As Byte()) As Integer

    Dim value As Integer

    ' Create GCHandle instance and pin variable required.
    Dim handle As GCHandle = GCHandle.Alloc(value, GCHandleType.Pinned)

    ' Get address of variable in pointer variable.
    Dim address As IntPtr = handle.AddrOfPinnedObject()

    ' Use copy method to copy array data to variable’s
    ' address with length specified(4)
    Marshal.Copy(byteArray, 0, address, 4)

    'First read value of variable from its address
    'in memory in order to use it
    value = Marshal.ReadInt32(address)

    ' Free the memory pointer.

    Return value

  End Function   'ByteArrayToInteger


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.