Sign in to follow this  
Followers 0
Joe

Can't get DllCall to work

6 posts in this topic

Hi, I want to use DLL functions in my script, but can't get it to work. I've tried DllCall, but nothing happens.

This is the code in C#

using System;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {
        [DllImport("packet.dll")]
        private static extern bool SendPacket(uint processID, byte[] packet);

        static void Main(string[] args)
        {
            new TestSendPacket();
        }

        public class TestSendPacket
        {
            public byte[] packet;
            public TestSendPacket()
            {
                packet = new byte[3];
                packet[0] = 0x01;
                packet[1] = 0x00;
                packet[2] = 0x65;
                SendPacket(3136, packet);
            }
        }

VB Code

Private Declare Sub SendPacket Lib "packet.dll" (ByVal ProcessID As Long, ByRef Packet As Byte)



Private Sub Command1_Click()
  Dim ProcessID As Long
  Dim PacketBuffer(2) As Byte

  GetWindowThreadProcessId FindWindow("tibiaclient", vbNullString), ProcessID

  PacketBuffer(0) = &H10
  PacketBuffer(1) = &H0
  PacketBuffer(2) = &H65

  SendPacket ProcessID, PacketBuffer(0)

End Sub

This is how my Autoit Script looks like:

Global $packet[3]
$packet[0]=0x01
$packet[1]=0x00
$packet[2]=0x65
$ProcessId = WinGetProcess("[CLASS:TibiaClient]")

DllCall('packet.dll', '', 'SendPacket', 'long', $ProcessId, 'byte', $Packet)

When I launch the script nothing happens.

If I don't leave the returntype blank the script crash.

I would be really grateful if someone could help me.

Share this post


Link to post
Share on other sites



DllCall('packet.dll', 'none:cdecl', 'SendPacket', 'long', $ProcessId, 'byte', $Packet)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Did not work, Autoit crash. But thanks for trying.

Maybe there is no way to make it work? I've tried all different return types from the help file, they all made autoit crash.

Share this post


Link to post
Share on other sites

Try this:

Local $ProcessId
$bytearr=DllStructCreate("byte[3];")
DllStructSetData($bytearr,1,0x01,1)
DllStructSetData($bytearr,1,0x00,2)
DllStructSetData($bytearr,1,0x65,3)
DllCall("packet.dll","int:cdecl","SendPacket","long",$ProcessId,"ptr",DllStructGetPtr($bytearr))

If it still crashes, remove :cdecl.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Well, why don't you use wpcap.dll? possibly your packet.dll has another function call as described here. http://www.winpcap.org/pipermail/winpcap-u...ust/000243.html (it*s from 2005, but i think, this is still true)


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Try this:

Local $ProcessId
$bytearr=DllStructCreate("byte[3];")
DllStructSetData($bytearr,1,0x01,1)
DllStructSetData($bytearr,1,0x00,2)
DllStructSetData($bytearr,1,0x65,3)
DllCall("packet.dll","int:cdecl","SendPacket","long",$ProcessId,"ptr",DllStructGetPtr($bytearr))

If it still crashes, remove :cdecl.

It worked! I only had to remove :cdecl.

I would never have figured out that myself, you are the best.

Thank you very much!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0