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?
http://www.google.com/search?hl=en&q=RtlMoveMemory+VB.NET&btnG=Google+Search
NONONONONONONONONONO
There is NO REASON to use CopyMemory in VB.NET.
Use the BitConverter class.
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.
@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
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: 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 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystembitconverterclasstopic.asp) is already implemented -- you don't need to implement it in your class.
I used BitConverter in my Buffer (http://cvs.sourceforge.net/viewcvs.py/jinxbot/Jinx/Jinx.Core/Net/Buffer.cs?rev=1.1&view=auto) and DataReader (http://cvs.sourceforge.net/viewcvs.py/jinxbot/Jinx/Jinx.Core/Net/DataReader.cs?rev=1.1&view=auto) classes because the StreamReader/StreamWriter classes (Part of System.IO) don't write data as consistently as I would like in my protocol.
erm should have said that diffrently
i meant how to use it
i did "Private Bit As System.BitConverter" but it didnt work
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);
i see
thanks :)
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"?
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.
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
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.