Originally Posted by
Azura
VB:
Private Declare Sub SendPacket Lib "packet.dll" (ByVal ProcessID As Long, ByVal Packet() As Byte)
As some might notice the Packet parameter in VB have changed to ByVal instead of the old ByRef, did this so the SafeArray parameter should not be needed to use. I have not tried this at all but if I got VB correct this should work.
This won't work, array parameters can only be passed by reference which will pass the address of the array varible which itself is a pointer to the arrays SAFEARRAY structure. Even if you could pass an array by value it would either simply create a copy of the array varible or a copy of the entire array (ie: SA pointer, SA structure and array data), in either case you would still have to deal with the SA structure.
You can get around all this SAFEARRAY mess by simply passing the address of the first byte in the actual array. This can easily be done by adjusting the 'Packet()' parameter to pass the address of a single byte instead of an array, effectively changing the function definition to the following:
Code:
Private\Public Declare Sub SendPacket Lib "packet.dll" (ByVal ProcessID As Long, ByRef Packet As Byte)
Now when you call the function instead of passing the array as a whole you simply pass the first byte in the array where the packet starts at, like so:
Code:
'Define a byte array to store the packet data in
Dim SomePacket(0 To 255) As Byte
'Send the packet, PacketStartOffset is the index of the array where the packet data (ie: first 2 bytes which specify the size of the encrypted packet + 4 for checksum)
SendPacket TibiaProcessID, SomePacket(PacketStartOffset)