• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1303
  • Last Modified:

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
0
ChiragDanech
Asked:
ChiragDanech
  • 3
  • 2
1 Solution
 
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.

Bob
0
 
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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.

Bob
0
 
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.
0
 
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.
    handle.Free()

    Return value

  End Function   'ByteArrayToInteger

Bob
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now