vb.net version of the cpymem api

Has anyone used the cpymem api in vb.net. Below is the vb6 version (which works) and the vb.net version (which does not work).  If you have gotten it to work in vb.net please send along a code sample.

Thanks
Bill

vb6 version
Private Declare Sub CpyMem Lib "kernel32" _
Alias "RtlMoveMemory" ( _
    pDst As Any, _
    pSrc As Any, _
    ByVal cBytes As Long _
)

vb.net version
Private Declare Sub CpyMem Lib "kernel32" _
    Alias "RtlMoveMemory" ( _
        ByVal pDst As Object, _
        ByVal pSrc As Object, _
        ByVal cBytes As Int32 _
    )
bill_homeAsked:
Who is Participating?
 
Bob LearnedCommented:
Yes, my friend, that is what I was alluding too.  I was under the impression that you want to use a Win32 API call.  It is "safer" to use the Marshal class.
0
 
Bob LearnedCommented:
I feel that it would be better to understand the differences between VB6 and VB.NET, and examine whether there is a .NET-way of achieving what you need.  Since .NET applications are "managed", API code is "unsafe", and if you can avoid using, I would suggest doing so.

Reference:

Equivalent of CopyMemory in .NET
http://www.codeproject.com/KB/vb/CopyMemory_in_Net.aspx

"The equivalent classes I am going to describe are System.Runtime.InteropServices.Marshal and System.Buffer."
0
 
bill_homeAuthor Commented:
I hear you TheLearnedOne, I had read the article you reference earlier today. The problems is time.....as I will have to write a bunch of procedures and of course I still have many more API's to get working in vb.net.  I am taking a program which was written in vb6 which capture audio, provides amplitude levels as well as a bunch of other functions..it is loaded with api's and types (which have to be converted to structs)

Amyway I have a ton of work to do and no time. So I was looking for a quick fix for cpymem.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Bob LearnedCommented:
Fair enough!!

For most of your Win32 API needs, turn to pinvoke.net

http://pinvoke.net/default.aspx/kernel32/MoveMemory.html

Private Declare Auto Sub MoveMemory Lib "Kernel32.dll" Alias "RtlMoveMemory" (ByVal dest As IntPtr, ByVal src As IntPtr, ByVal size As Integer)
0
 
Bob LearnedCommented:
If you have time to explain what you are working with, there might be an easier way to achieve that.
0
 
bill_homeAuthor Commented:
I will check into the api you provided. The api is just copying different data types to memory, Some are structs, some are arrays, etc.
0
 
bill_homeAuthor Commented:
TLO,
  Won't this work as well :

Dim ptr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(control))
 Marshal.StructureToPtr(control, ptr, False)

control is a structure. The doc's state that it moves data from a managed object to an unmanaged block of memory.  Seems like it would do the trick.


Bill
0
 
bill_homeAuthor Commented:
Tries  to teach not just do..
0
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.

All Courses

From novice to tech pro — start learning today.