Jump to content

Delphi Dll call


Recommended Posts

Hi

When i compile this project and call my dll through Delphi app it works perfectly but using autoit when i call dll it not responding donno why even it returned str project2.exe

DllCall("myapp.dll","none" ,StartProject, "str" ,"project2.exe")

Delphi code :

unit Unit1;

interface

uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, StdCtrls;

type
   TForm1 = class(TForm)
     Button1: TButton;
     Button2: TButton;
     procedure Button1Click(Sender: TObject);
     procedure Button2Click(Sender: TObject);
   private
     { Private declarations }
   public
     { Public declarations }
   end;

var
   Form1: TForm1;
   procedure StartProject(MyFileName: Pchar); stdcall; external 'myapp.dll';
   procedure StopProject; stdcall; external 'myapp.dll';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  StartProject('project2.exe');
 
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
    StopProject;
end;

end.
Link to comment
Share on other sites

hi again autoitxp,

Why did you abandon :huh2:

When using DllCall, the function name must be enclosed in quotes ;), try it like this:

DllCall("myapp.dll", "none", "StartProject", "str", "project2.exe")

Hope this helps,

-smartee

Link to comment
Share on other sites

DllCall("myapp.dll", "none:cdecl", "StartProject", "str", "project2.exe")

returned nothing and script terminated .

dll is very fine all function working well with my Delphi project. only facing problem when calling through Auto-it

Link to comment
Share on other sites

This gives you detailed error message

$aRet = DllCall("myapp.dll", "none", "StartProject", "str", "project2.exe")
_GetLastErrorMessage('Result')

Func _GetLastErrorMessage($DisplayMsgBox="")
    Local $ret,$s
    Local $p    = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM        = 0x00001000

    If @error Then Return ""

    $ret    = DllCall("Kernel32.dll","int","GetLastError")

    $ret    = DllCall("kernel32.dll","int","FormatMessage", _
                        "int",$FORMAT_MESSAGE_FROM_SYSTEM, _
                        "ptr",0, _
                        "int",$ret[0], _
                        "int",0, _
                        "ptr",DllStructGetPtr($p), _
                        "int",4096, _
                        "ptr",0)
    $s    = DllStructGetData($p,1)
    $p = 0
    If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s)
    return $s
EndFunc
Edited by Zedna
Link to comment
Share on other sites

autoitxp,

@error=0 means your DllCall was successful, as you may have figured out by now. However, it obviously doesn't do what you expected, so..

..the "problem" might be in the function itself, or its declaration..

has some examples if you need them :huh2:

-smartee

Link to comment
Share on other sites

Since there seems to be nothing wrong with the AutoIt code, and the Delphi example works you must conclude there is something wrong you haven't thought of.

Delphi is only 32 bit, so are you compiling AutoIt for 64 bit?

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

auto-it Script 32bit uncompressed not 64bit

delphi-dll 32bit

i just cannot figure out dll seem works fine using Delphi i rechecked nothing found bad in dll

next function it called is this may help u to find problem ?

Function StartProjectStru(NextFile : PChar ; Bufx : Pointer) : integer;stdcall;

but this func doesn't need to called from autoit.

when i tried this way it call dll and works but terminated in secs

DllCall("myapp.dll", "none", "StartProject", "str", "project2.exe" ,"ptr", 0)
!>20:28:21 AutoIT3.exe ended.rc:-1073741819
Edited by autoitxp
Link to comment
Share on other sites

auto-it Script 32bit uncompressed not 64bit

delphi-dll 32bit

i just cannot figure out dll seem works fine using Delphi i rechecked nothing found bad in dll

next function it called is this may help u to find problem ?

Function StartProjectStru(NextFile : PChar ; Bufx : Pointer) : integer;stdcall;

but this func doesn't need to called from autoit.

when i tried this way it call dll and works but terminated in secs

DllCall("myapp.dll", "none", "StartProject", "str", "project2.exe" ,"ptr", 0)
!>20:28:21 AutoIT3.exe ended.rc:-1073741819

What version of Delphi are you using?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

hi autoitxp,

We know the outcome you achieve, and it seems perfect, because we do not know what is expected.

The next function called within your Delphi program has little to do with your original DllCall. Rather, I suspect the error lies in what you expect the dll to do once called from AutoIt, not in the DllCall, thus creating the obvious question:

What exactly does the procedure do? is it a popup message? does it write to a file? How do you know it isn't being called?

Try putting a ShowMessage() as the first line of your procedure, and tell us if you see it :huh2:

;)

-smartee

Link to comment
Share on other sites

Then "str" should be ok for the parameter.

0 for the "ptr" probably upsets the dll though.

Are you willing to show or share the code for the dll?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

-smartee your ShowMessage() trick worked i found Delphi first loads this func

Function NtQuerySystemInformation(infoClass: DWORD;
                                      buffer: Pointer;
                                      bufSize: DWORD;
                                      returnSize: TPDWord): DWORD; stdcall;

I Put ShowMessage() in start of all function and delphi load this first and auto-it just didn't popped up message when i called dll it means i need to define separately to call NtQuerySystemInformation first then StartProject ?

Edited by autoitxp
Link to comment
Share on other sites

I called this function it pop up message and stops now what next how to to call StartProject?

Global Const $SystemProcessInformation = 5
 DllCall("mydll.dll", "int", "NtQuerySystemInformation", _
                                    "int", $SystemProcessInformation, _
                                    "ptr", 0, _
                                    "int", 0, _
                                    "int*", 0)
Link to comment
Share on other sites

SystemInformation [in, out]

A pointer to a buffer that receives the requested information. The size and structure of this information varies depending on the value of the SystemInformationClass parameter:

SYSTEM_BASIC_INFORMATION

When the SystemInformationClass parameter is SystemBasicInformation, the buffer pointed to by the SystemInformation parameter should be large enough to hold a single SYSTEM_BASIC_INFORMATION structure having the following layout:

Copy

typedef struct _SYSTEM_BASIC_INFORMATION {

BYTE Reserved1[24];

PVOID Reserved2[4];

CCHAR NumberOfProcessors;

} SYSTEM_BASIC_INFORMATION;

The NumberOfProcessors member contains the number of processors present in the system. Use GetSystemInfo instead to retrieve this information.

The other members of the structure are reserved for internal use by the operating system.

You seen to be passing a null pointer to that param.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...