Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Delphi] Calling functions from a DLL

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
assaf84
Expert Cheater
Reputation: 0

Joined: 03 Oct 2006
Posts: 238

PostPosted: Sun Sep 23, 2007 12:42 am    Post subject: [Delphi] Calling functions from a DLL Reply with quote

I made a DLL in C, and I can call it's functions from application in C like this:
Code:
#include <stdio.h>
#include <windows.h>
#include <conio.h>

BYTE (__stdcall *ListProcesses)(LPVOID);

void __stdcall ListFunc(char* FileName, DWORD pID, BYTE flag)
{
   if(!flag)
      printf("%s\t%X\n",FileName,pID);
}

void main()
{

   printf("Starting...");
   HMODULE myDLL = LoadLibrary("Injecting.dll");
   ListProcesses = (BYTE (__stdcall *)(LPVOID))GetProcAddress(myDLL,"ListProcesses");

   printf("\n");
   ListProcesses( (LPVOID)ListFunc );

   printf("\nDone!");
   getch();
}


But when I try to do it in delphi it gives me errors =\
Code:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;

    procedure FillList(FileName: String; pID: DWORD; flag: BYTE); stdcall;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }


  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  assaf: tstringlist;

  function ListProcesses(CallbackFunction: DWORD):BYTE; stdcall; external 'Injecting.dll';


implementation

{$R *.dfm}

procedure TForm1.FillList(FileName: String; pID: DWORD; flag: BYTE); stdcall;
begin

if flag=0 then
  ListBox1.Items.Add(FileName);

end;




procedure TForm1.Button1Click(Sender: TObject);
begin
ListProcesses(DWORD(@TForm1.FillList));
end;



end.



What's wrong?
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Sun Sep 23, 2007 3:43 am    Post subject: Reply with quote

wat the dll is doing?
if you can upload the dll this will be good.
Back to top
View user's profile Send private message
Programmer
Cheater
Reputation: 0

Joined: 02 Sep 2007
Posts: 48

PostPosted: Sun Sep 23, 2007 6:28 am    Post subject: Reply with quote

HolyBlah wrote:
wat the dll is doing?
if you can upload the dll this will be good.


That makes no diference.

_________________
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Sun Sep 23, 2007 6:35 am    Post subject: Reply with quote

Try:

Code:


function {function name: boolean or w.e}
stdcall;
external 'MyDll.dll'

Procedure Button1Click
Begin
{function name: boolean or w.e}
End;



Edit: lol nvm, i just saw that you did the same method asi i did, and i get errors too ><"

i asked db the same question nad he said he used GetProcAddress, he said "if you want an example, take a look in newkernelhandler.pas", he calls functions from his dll's there.
Back to top
View user's profile Send private message
assaf84
Expert Cheater
Reputation: 0

Joined: 03 Oct 2006
Posts: 238

PostPosted: Sun Sep 23, 2007 6:52 am    Post subject: Reply with quote

I think my problem is in the callback function actually.. I have no idea what is it, though... Well, I'll use getProcAddress and check it anyway..

Edit: Won't work with GetProcAddress... I'm pretty sure it has to do with the call back function..

Edit2: Solved. I put this function out of TForm1 class, and instead of String as first parameter I put PChar. I alos needed to make a stringlist, because ListBox1 was part of TForm1 class..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites