• Welcome to Valhalla Legends Archive.
 

[VB .NET]CopyMemory

Started by Mangix, September 01, 2005, 12:47 AM

Previous topic - Next topic

Mangix

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

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long) 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?


MyndFyre

NONONONONONONONONONO

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

Use the BitConverter class.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

dxoigmn

Quote from: MyndFyre on September 01, 2005, 02:33 AM
NONONONONONONONONONO

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

Use the BitConverter class.

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.

Mangix

#4
@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

Warrior

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
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

MyndFyre

Quote from: Mangix on September 01, 2005, 01:06 PM
@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

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Mangix

erm should have said that diffrently

i meant how to use it

i did "Private Bit As System.BitConverter" but it didnt work

K

Quote from: Mangix on September 01, 2005, 01:50 PM
erm should have said that diffrently

i meant how to use it

i did "Private Bit As System.BitConverter" but it didnt work

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


int32 value = System.BitConverter.ToInt32(SomeByteArray, SomeIndex);

Mangix


dxoigmn

Quote from: MyndFyre on September 01, 2005, 01:45 PM
... because the StreamReader/StreamWriter classes (Part of System.IO) don't write data as consistently as I would like in my protocol.

Hmm? What do you mean "don't write data as consistently"?

MyndFyre

Quote from: dxoigmn on September 01, 2005, 06:12 PM
Quote from: MyndFyre on September 01, 2005, 01:45 PM
... because the StreamReader/StreamWriter classes (Part of System.IO) don't write data as consistently as I would like in my protocol.

Hmm? What do you mean "don't write data as consistently"?

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

OlOOOlll

Quote from: MyndFyre on September 01, 2005, 02:33 AM
NONONONONONONONONONO

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

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


    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

MyndFyre

Quote from: OlOOOlll on December 03, 2005, 09:55 AM
well i wish i had seen this before i spent 3 hrs makeing these ;/
Yeah.... that's a pretty good example of how not to do things in .NET.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.