Author | Message | Time |
---|---|---|
vector | I have declared CopyMemory as follows: [code] Private Declare Sub CopyMemory Lib "kernel32" Alias "rtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long) [/code] 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. | November 24, 2008, 11:14 PM |
Ringo | [quote author=vector link=topic=17723.msg180565#msg180565 date=1227568489] I have declared CopyMemory as follows: [code] Private Declare Sub CopyMemory Lib "kernel32" Alias "rtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long) [/code] 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. [/quote] It's RtlMoveMemory, not rtlMoveMemory :p | November 24, 2008, 11:38 PM |
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? | November 25, 2008, 2:33 AM |
Barabajagal | The actual name of the function is RtlMoveMemory, not CopyMemory. | November 25, 2008, 2:39 AM |
FrostWraith | Back in the day when I did VB programming, here was how I declared it. [code]Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ (ByRef Destination As Any, ByRef Source As Any, ByVal numBytes As Long)[/code] | November 25, 2008, 3:16 AM |
vector | Freaking Kernel32.DLL .. I'll try that next time. | November 25, 2008, 5:01 AM |
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. | December 2, 2008, 12:28 AM |
Barabajagal | Paste your declaration and how you're calling it. | December 2, 2008, 1:00 AM |
l2k-Shadow | [quote author=vector link=topic=17723.msg180602#msg180602 date=1228177724] Even if I declare it properly, it crashes the client. Anyone know anything about this? I can post technical information if someone requests it. [/quote] 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: [code] Dim a As String a = String$(4, vbNullChar) CopyMemory ByVal a, &H6A6B6C6D, 4 [/code] | December 2, 2008, 2:26 AM |
vector | Declaration: [code]Private Declare Sub CopyMemory Lib "kernel32" Alias "rtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)[/code] 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: [code] 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 [/code] | December 2, 2008, 8:44 PM |
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. | December 2, 2008, 9:19 PM |
Ringo | [quote author=vector link=topic=17723.msg180622#msg180622 date=1228250678] Declaration: [code]Private Declare Sub CopyMemory Lib "kernel32" Alias "rtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)[/code] 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: [code] 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 [/code] [/quote] 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: [code] dim newValue as string * 2 Call CopyMemory(ByVal newValue, Clng(Len(sOut) + 4), 2) [/code] If you want to copy a string, into a long, then: [code] dim newValue as string * 4 dim newLong as long newValue =chr(17) & chr(20) & chr(1) & chr(0) Call CopyMemory(newLong, ByVal newValue, 4) [/code] if you want to copy part of a string to a numeric value, then: [code] 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) [/code] when passing numeric values byvalue: [code] 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[/code] and so on | December 2, 2008, 10:13 PM |
Ribose | [quote author=vector link=topic=17723.msg180622#msg180622 date=1228250678] Declaration: [code]Private Declare Sub CopyMemory Lib "kernel32" Alias "rtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)[/code] [/quote][quote author=Ringo link=topic=17723.msg180566#msg180566 date=1227569920] It's RtlMoveMemory, not rtlMoveMemory :p [/quote] o.o | December 20, 2008, 3:44 PM |