[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

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 _
    )
0
bill_home
Asked:
bill_home
  • 4
  • 4
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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