| View previous topic :: View next topic |
| Author |
Message |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Sun Sep 23, 2007 12:42 am Post subject: [Delphi] Calling functions from a DLL |
|
|
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 |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Sun Sep 23, 2007 3:43 am Post subject: |
|
|
wat the dll is doing?
if you can upload the dll this will be good.
|
|
| Back to top |
|
 |
Programmer Cheater
Reputation: 0
Joined: 02 Sep 2007 Posts: 48
|
Posted: Sun Sep 23, 2007 6:28 am Post subject: |
|
|
| HolyBlah wrote: | wat the dll is doing?
if you can upload the dll this will be good. |
That makes no diference.
_________________
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Sep 23, 2007 6:35 am Post subject: |
|
|
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 |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Sun Sep 23, 2007 6:52 am Post subject: |
|
|
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 |
|
 |
|