Valhalla Legends Forums Archive | .NET Platform | [VB .NET]CopyMemory

AuthorMessageTime
Mangix
ok im trying to Declare the CopyMemory API into VB 2005 but im running into a few problems

[code]Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)[/code] is the correct usage in VB however in VB .NET i cant use As Any. so i made it As Variant. when i did it made it As Object which is really pissing me off.

does anyone know how i can fix this?
September 1, 2005, 5:47 AM
kamakazie
http://www.google.com/search?hl=en&q=RtlMoveMemory+VB.NET&btnG=Google+Search
September 1, 2005, 6:41 AM
Myndfyr
NONONONONONONONONONO

There is NO REASON to use CopyMemory in VB.NET.

Use the BitConverter class.
September 1, 2005, 7:33 AM
kamakazie
[quote author=MyndFyre link=topic=12683.msg126461#msg126461 date=1125560005]
NONONONONONONONONONO

There is NO REASON to use CopyMemory in VB.NET.

Use the BitConverter class.
[/quote]

Hehe. I was debating whether or not to point that out but I figured let him learn the hard way since he'd probably learn a lot that way.
September 1, 2005, 9:09 AM
Mangix
@MyndFire: thanks :)

edit: sooooooo how would i go on about implementing the BitConverter Class in my class?

also note im fairly new to .NET so i dont know everything
September 1, 2005, 6:06 PM
Quarantine
Isn't there a MemoryStream or something? I saw a hint of that in Jinx's buffer I was taking a look at, of course it can be C# specific
September 1, 2005, 6:14 PM
Myndfyr
[quote author=Mangix link=topic=12683.msg126495#msg126495 date=1125598006]
@MyndFire: thanks :)

edit: sooooooo how would i go on about implementing the BitConverter Class in my class?

also note im fairly new to .NET so i dont know everything
[/quote]

The BitConverter class is already implemented -- you don't need to implement it in your class.

I used BitConverter in my Buffer and DataReader classes because the StreamReader/StreamWriter classes (Part of System.IO) don't write data as consistently as I would like in my protocol.
September 1, 2005, 6:45 PM
Mangix
erm should have said that diffrently

i meant how to use it

i did "Private Bit As System.BitConverter" but it didnt work
September 1, 2005, 6:50 PM
K
[quote author=Mangix link=topic=12683.msg126502#msg126502 date=1125600640]
erm should have said that diffrently

i meant how to use it

i did "Private Bit As System.BitConverter" but it didnt work
[/quote]

The BitConverter class is static (or "Shared" in VB.NET).  You don't need to create an instance of it.

[code]
int32 value = System.BitConverter.ToInt32(SomeByteArray, SomeIndex);
[/code]
September 1, 2005, 7:27 PM
Mangix
i see

thanks :)
September 1, 2005, 7:35 PM
kamakazie
[quote author=MyndFyre link=topic=12683.msg126499#msg126499 date=1125600346]
... because the StreamReader/StreamWriter classes (Part of System.IO) don't write data as consistently as I would like in my protocol.
[/quote]

Hmm? What do you mean "don't write data as consistently"?
September 1, 2005, 11:12 PM
Myndfyr
[quote author=dxoigmn link=topic=12683.msg126560#msg126560 date=1125616362]
[quote author=MyndFyre link=topic=12683.msg126499#msg126499 date=1125600346]
... because the StreamReader/StreamWriter classes (Part of System.IO) don't write data as consistently as I would like in my protocol.
[/quote]

Hmm? What do you mean "don't write data as consistently"?
[/quote]

I mean that I wanted it to be able to write C- or Pascal-style strings and BinaryWriter/BinaryReader doesn't support it.  It seemed silly to have an extra object when a non-object class supported the same operations I wanted.
September 1, 2005, 11:19 PM
OlOOOlll
[quote author=MyndFyre link=topic=12683.msg126461#msg126461 date=1125560005]
NONONONONONONONONONO

There is NO REASON to use CopyMemory in VB.NET.

Use the BitConverter class.
[/quote]
well i wish i had seen this before i spent 3 hrs makeing these ;/

[code]
    Public Sub CopyMemory(ByRef Destination As String, ByRef Source As Integer, ByVal Length As Short)
        Dim [String] As String = Hex$(Source)
        Dim i As Integer
        Dim l As Short
        Destination = ""
        For i = 1 To Len([String]) Step 2
            If Len([String]) > 1 Then
                l = 2
            Else : l = 1
            End If
            Destination = Destination & Right([String], l)
            [String] = Left([String], Len([String]) - l)
        Next
        [String] = Destination
        Destination = ""

        For i = 1 To Len([String]) Step 2
            Destination = Destination & Chr(CInt("&H" & Mid$([String], i, 2)))
        Next i

        While Len(Destination) < Length
            Destination = Destination & Chr(0)
        End While
    End Sub

    Public Sub CopyMemory(ByRef Destination As Integer, ByVal Source As String)
        Dim i As Integer
        Dim [String] As String = ""
        For i = 1 To Len(Source)
            [String] = Hex(Asc(Mid(Source, i, 2))) & [String]
        Next i
        Destination = CInt("&H" & [String])
    End Sub
[/code]
December 3, 2005, 3:55 PM
Myndfyr
[quote author=OlOOOlll link=topic=12683.msg136204#msg136204 date=1133625342]
well i wish i had seen this before i spent 3 hrs makeing these ;/
[/quote]
Yeah.... that's a pretty good example of how not to do things in .NET.
December 3, 2005, 10:36 PM

Search