473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

use copymemory api in vb.net

I am facing a problem in copymemory api in vb.net .
the problem is that i have used copymemory api extensively in my
project originally written in vb6.0 ,
now when i'm migrating my project to vb.net "as any"is not supported
over here.
so my code having copymemory is not upgraded.
i can't overload copymemory api as i mainly use copymemory api to copy
user defined structures to byte array and vice versa and i have lot
many of these structures.
so please provide me with some way out.
Nov 20 '05 #1
5 6948
On 2003-11-25, RaviAmbani <ra**********@yahoo.com> wrote:
I am facing a problem in copymemory api in vb.net .
the problem is that i have used copymemory api extensively in my
project originally written in vb6.0 ,
now when i'm migrating my project to vb.net "as any"is not supported
over here.
so my code having copymemory is not upgraded.
i can't overload copymemory api as i mainly use copymemory api to copy
user defined structures to byte array and vice versa and i have lot
many of these structures.
so please provide me with some way out.


This is sort of a general answer - since I'm not sure exactly what
circumstances you were using CopyMemory in the past - but in general
there are ways of accomplishing this sort of thing with in the
framework, without resorting to using CopyMemory. Maybe, if you were to
post a sinipit of VB.CLASSIC code that you are trying to convert
(including relevant structure definitions), we might be able to come up
with a more specific solution.

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #2
* ra**********@yahoo.com (RaviAmbani) scripsit:
I am facing a problem in copymemory api in vb.net .
the problem is that i have used copymemory api extensively in my
project originally written in vb6.0 ,
now when i'm migrating my project to vb.net "as any"is not supported
over here.
so my code having copymemory is not upgraded.
i can't overload copymemory api as i mainly use copymemory api to copy
user defined structures to byte array and vice versa and i have lot
many of these structures.


It depends on the situation. Sometimes you can replace the calls with
calls to 'System.Runtime.InteropServices.Marshal.*'. It's easier to
help if you post some code.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
I m sending you some sample code that i want to convert from VB to
VB.NET...
that uses CopyMemory API.
------------------------------
Private Sub Command1_Click()
Dim lretval As Long
Dim udtdate As SYSTEMTIME
Dim udtdate1 As SYSTEMTIME
Dim btarray() As Byte
Dim sfinaldate As String * 20
Dim sfinaldate1 As String * 20
udtdate.wMonth = 12
udtdate.wDay = 12
udtdate.wYear = 2003
lretval = GetDateFormatA(1033, 0, udtdate, Replace("mm/dd/yyyy", "m",
"M"), sfinaldate, 20)
ReDim btarray(0)
Call CopyMemory(btarray(0), udtdate, Len(udtdate))
Call CopyMemory(udtdate1, btarray(0), Len(udtdate1))
MsgBox "d", vbInformation
End Sub
-----------------------

Thanx.
Ravi
Nov 20 '05 #4
"RaviAmbani" <ra**********@yahoo.com> schrieb
I m sending you some sample code that i want to convert from VB to
VB.NET...
that uses CopyMemory API.
------------------------------
Private Sub Command1_Click()
Dim lretval As Long
Dim udtdate As SYSTEMTIME
Dim udtdate1 As SYSTEMTIME
Dim btarray() As Byte
Dim sfinaldate As String * 20
Dim sfinaldate1 As String * 20
udtdate.wMonth = 12
udtdate.wDay = 12
udtdate.wYear = 2003
lretval = GetDateFormatA(1033, 0, udtdate, Replace("mm/dd/yyyy",
"m", "M"), sfinaldate, 20)
ReDim btarray(0)
Call CopyMemory(btarray(0), udtdate, Len(udtdate))
Call CopyMemory(udtdate1, btarray(0), Len(udtdate1))
MsgBox "d", vbInformation
End Sub
-----------------------

Thanx.
Ravi


Untested:
Have a look at the ToString function of a DateTime object. The function is
overloaded and you can pass an object implementing System.IFormatProvider.
Create a new CultureInfo object using the destination culture you want the
string to be formatted for. It's DateTimeFormat property returns a
System.Globalization.DateTimeFormatInfo object. As it implements
IFormatProvider, you can pass it to the ToString function of a DateTime
object.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
Ravi,
I m sending you some sample code that i want to convert from VB to
VB.NET...
Better rewrite it, the code is pretty bad.

lretval = GetDateFormatA(1033, 0, udtdate, Replace("mm/dd/yyyy", "m",
"M"), sfinaldate, 20)
I don't see any reason to call GetDateFormat in VB.NET. As Armin said,
the DateTime type can do this formatting for you.

And what's with the Replace call? Why not type "MM/dd/yyyy" directly?

ReDim btarray(0)
Call CopyMemory(btarray(0), udtdate, Len(udtdate))
Call CopyMemory(udtdate1, btarray(0), Len(udtdate1))
I'm surprised that this code doesn't crash. What you're doing is to
copy a 16-byte SYSTEMTIME structure into a 1-byte array, an ugly
buffer overflow bug. Plus, the CopyMemory calls seem unnecessary,
since you just as well could do

udtdate1 = udtdate

MsgBox "d", vbInformation


Now that's useful. "d"!

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mikael Lundberg | last post by:
Hi! Just one question Is it legal to copy the array descriptor in this way : Dim lngArr1() as Long Dim lngArr2() as Long Redim lngArr1(2) as Long
5
by: active | last post by:
Has anyone used CopyMemory with DotNet? In this instance I define it as: Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (ByRef hpvDest As DEVMODE, ByRef hpvSource As Byte,...
9
by: Paul W | last post by:
Hello Group, I'm a .net newbie with a couple of questions. First, Debug.WriteLine() doesn't send any output to the immediate window, anybody know why that might be? Second, what is the .net...
4
by: Turtle | last post by:
I've been using SendKeys to automate a small utility which doesn't expose an automation interface, but ran into a problem, for which I found the suggestion that I use the WinAPI SendInput call...
10
by: Dennis | last post by:
I am trying to use CopyMemory to copy arrays as follows: Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal pDst As Long, ByVal pSrc As Long, ByVal ByteLen As Integer) ...
0
by: android | last post by:
Hi all. I should migrate old vb6 code in vb.net but I been clashed with the copymemory api! Here below is a vb6 method that manages the current sample of a waveform file in a buffer for retrieving...
0
by: akumar | last post by:
Hello Please send me the syntax of CopyMemory function in VB.net thnax akumar
3
by: vb newbie | last post by:
I need to copy the contents of one byte array to another one. I was hoping to do it quickly uisng the CopyMemory api call. However, I'm getting: FatalExecutionEngineError was detected...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.