Sigh:
First, Jacob is correct you need to create a thread. Your original way will just crash Gunz.
Second, Jacob doesn't know Delphi(no offense). You have to use BeginThread() not CreateThread() or use TThread object.
Correct example(no I didn't test this):
Code:
library ZChat;
uses
SysUtils,
Classes,
Windows;
//include the windows file
const
ADDRESS = $0042A230; // address for the ZChatOutPut
type
TZChatoutput = procedure (char : Pchar; int1 : integer; int2 :integer; Colour:Dword); cdecl;
var
ZChatOutput : TZChatoutput = TZChatOutput(ADDRESS);
ThreadID : Integer;
procedure Echo(Output: String);
var
Buffer : PAnsiChar;
begin
If Length(Output) < 200 Then
begin
If @ZChatOutput <> nil Then
begin
Buffer := AllocMem(200);
Try
StrPCopy(Buffer,Output);
ZChatOutput(Buffer,0,0,$FFFFFFFF);
Finally
FreeMem(Buffer);
end;
end;
end;
end;
function ChatThread(Data: Pointer): Integer;
begin
Result := 0;
While True Do
begin
If GetAsyncKeyState(VK_MENU) <> 0 then // Check if ALT was pressed
begin
Echo('hello world from dll');
end;
Sleep(10);
end;
end;
//EntryPoint for DLL
Procedure Entrypoint( Reason :DWORD);
var
ID1 : DWORD;
begin
if Reason = DLL_PROCESS_ATTACH then begin
ThreadID := BeginThread(nil,0,@ChatThread,nil,0,ID1);
end;
if Reason = DLL_PROCESS_DETACH then begin
TerminateThread(ThreadID,0);
CloseHandle(ThreadID);
end;
end;
begin
DLLProc := @EntryPoint;
EntryPoint(DLL_PROCESS_ATTACH);
end.