• Welcome to Valhalla Legends Archive.
 

*sigh* DLL Entry Point in CopyMemory

Started by vector, November 24, 2008, 05:14 PM

Previous topic - Next topic

vector

I have declared CopyMemory as follows:


Private Declare Sub CopyMemory Lib "kernel32" Alias "rtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)


Now when it comes to that function, I get a "Can't find DLL entry point CopyMemory in kernel32.dll"

Is there a specific reason for this? I've looked places, but was unable to find a definite answer.

Ringo

Quote from: vector on November 24, 2008, 05:14 PM
I have declared CopyMemory as follows:


Private Declare Sub CopyMemory Lib "kernel32" Alias "rtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)


Now when it comes to that function, I get a "Can't find DLL entry point CopyMemory in kernel32.dll"

Is there a specific reason for this? I've looked places, but was unable to find a definite answer.
It's RtlMoveMemory, not rtlMoveMemory :p

vector

I even removed that line, and it says that it can't find a DLL entry point in CopyMemory.

I wouldn't happen to need that alias, wouldn't I?

Barabajagal

The actual name of the function is RtlMoveMemory, not CopyMemory.

FrostWraith

Back in the day when I did VB programming, here was how I declared it.
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (ByRef Destination As Any, ByRef Source As Any, ByVal numBytes As Long)

vector

Freaking Kernel32.DLL ..

I'll try that next time.

vector

Even if I declare it properly, it crashes the client.

Anyone know anything about this?

I can post technical information if someone requests it.

Barabajagal

Paste your declaration and how you're calling it.

l2k-Shadow

Quote from: vector on December 01, 2008, 06:28 PM
Even if I declare it properly, it crashes the client.

Anyone know anything about this?

I can post technical information if someone requests it.

you have to make sure you are using it correctly. such as making sure that what you are copying into a variable that has been allocated in memory.
ex:

Dim a As String
a = String$(4, vbNullChar)
CopyMemory ByVal a, &H6A6B6C6D, 4
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

vector

Declaration:

Private Declare Sub CopyMemory Lib "kernel32" Alias "rtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)

Right now, I only have one packet that I send, because I want to figure out whats wrong before I continue with the others. It is BNLS_0x0E (BNLS_AUTHORIZE)

That's fine.

When I get to sending the packet, here is my SendPacket function:


Public Sub sendPacket(ByVal ID As Byte)
  Dim newValue As String * 2

  If BNCSFlag = True Then
    CopyMemory newValue, ByVal (Len(sOut) + 4), 4
    If frmMain.sckBNLS.State = sckConnected Then
      frmMain.sckBNLS.SendData newValue & Chr$(ID) & sOut
      botDebug.add "Packet sent (Type: BNLS): 0x" & Hex(ID)
    End If
  Else
    CopyMemory newValue, ByVal (Len(sOut) + 4), 4
    If frmMain.sckBNET.State = sckConnected Then
      frmMain.sckBNET.SendData Chr$(&HFF) & Chr$(ID) & newValue & sOut
      botDebug.add "Packet sent (Type: BNCS): 0x" & Hex(ID)
    End If
  End If
End Sub

l2k-Shadow

a) you're copying 4 bytes into a variable initialized for 2 bytes
b) you have to pass the destination variable by value, and the source by reference, as according to your declaration.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Ringo

Quote from: vector on December 02, 2008, 02:44 PM
Declaration:

Private Declare Sub CopyMemory Lib "kernel32" Alias "rtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)

Right now, I only have one packet that I send, because I want to figure out whats wrong before I continue with the others. It is BNLS_0x0E (BNLS_AUTHORIZE)

That's fine.

When I get to sending the packet, here is my SendPacket function:


Public Sub sendPacket(ByVal ID As Byte)
  Dim newValue As String * 2

  If BNCSFlag = True Then
    CopyMemory newValue, ByVal (Len(sOut) + 4), 4
    If frmMain.sckBNLS.State = sckConnected Then
      frmMain.sckBNLS.SendData newValue & Chr$(ID) & sOut
      botDebug.add "Packet sent (Type: BNLS): 0x" & Hex(ID)
    End If
  Else
    CopyMemory newValue, ByVal (Len(sOut) + 4), 4
    If frmMain.sckBNET.State = sckConnected Then
      frmMain.sckBNET.SendData Chr$(&HFF) & Chr$(ID) & newValue & sOut
      botDebug.add "Packet sent (Type: BNCS): 0x" & Hex(ID)
    End If
  End If
End Sub

As shadow said, you're copying 4 bytes into a 2 bytes.
You're also useing len(buffer)+4 for the BNLS header, should be +3 :p
That aside, when passing a string as "any", you must pass it byval.
When passing a long as "any", you should pass it byref, unless you want to use an address space, then pass byval.
Example:

dim newValue as string * 2
Call CopyMemory(ByVal newValue, Clng(Len(sOut) + 4), 2)

If you want to copy a string, into a long, then:

dim newValue as string * 4
dim newLong as long
newValue =chr(17) & chr(20) & chr(1) & chr(0)
Call CopyMemory(newLong, ByVal newValue, 4)

if you want to copy part of a string to a numeric value, then:

dim newValue as string * 4
dim newInt as integer
newValue =chr(17) & chr(20) & chr(1) & chr(0)
Call CopyMemory(newInt, ByVal mid$(newValue, 2, 2), 2)

when passing numeric values byvalue:

dim long1 as long
dim long2 as long
long1 =&H12345678
Call CopyMemory(long2, long1, 4) 'aka long2 = long1
Call CopyMemory(long2, byval varptr(long1), 4) 'aka long2 = long1
Call CopyMemory(long2, byval varptr(long1)+1, 2) 'aka long2 =middle 2 byts of long1

and so on

Ribose

Quote from: vector on December 02, 2008, 02:44 PM
Declaration:

Private Declare Sub CopyMemory Lib "kernel32" Alias "rtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Quote from: Ringo on November 24, 2008, 05:38 PM
It's RtlMoveMemory, not rtlMoveMemory :p
o.o
~Ribose